std/regex documentation

std/regex▲toc

Regular expressions.

The regular expressions conform to the regular expressions of JavaScript as described at https://​developer.​mozilla.​org/​en-​US/​docs/​Web/​JavaScript/​Guide/​Regular_​Expressions.

type groupsstd/regex/groups: V

Return the string captured by a particular group or the empty string.

For alternative regular expressions, return the alternative that was matched. If this was not an alternative regex, returns -1.

Return the first matched group (or “” if nothing matched) starting at start and returning at most group end.

Return first group that was matched (or -1 if nothing was matched).

Automatically generated. Retrieves the groups constructor field of the matchedstd/regex/matched: V type.

Returns Truestd/core/True: bool if a particular capture group actually matched. This is used if the group can match, but may capture the empty string.

struct matchedstd/regex/matched: V(slice : sslicestd/core/sslice: Vmatched : stringstd/core/string: Vgroups : groupsstd/regex/groups: V)

The result of a regular expression match, where matched is the content that was matched, and groups is a vector that contains the content for each capture group (where groups[0] == matched). The slice field contains the sslicestd/core/sslice: V of the string that was matched.

Return the string following match.

Return the string following match but ensure we advance by at least 1 character (to ensure termination with empty matches).

Return the string before a match.

Automatically generated. Retrieves the matched constructor field of the matchedstd/regex/matched: V type.

Automatically generated. Retrieves the slice constructor field of the matchedstd/regex/matched: V type.

type regexstd/regex/regex: V

Abstract type of a regular expression object.

How many groups are captured by this regex?

Create a new regular expression. Takes two optional parameters. Set ignoreCase to Truestd/core/True: bool to ignore uppercase/lowercase distinction. If multiline is set to Truestd/core/True: bool, then ^ and $ match also the beginning and end of every line (instead of the entire input).

Create a new alternative regular expression. Matches any of the given patterns but the groups are local to each alternative. See alternativestd/regex/alternative: (groups : groups) -> int to find out which alternative was matched. Contains an optimization where a common prefix of all patterns is lifted out of the alternative to increase efficiency. Takes two optional parameters. Set ignoreCase to Truestd/core/True: bool to ignore uppercase/lowercase distinction. If multiline is set to Truestd/core/True: bool, then ^ and $ match also the beginning and end of every line (instead of the entire input).
Note: currently only supported in the javascript backend.

Return the pattern as a string.

fun contains( s : stringstd/core/string: V, r : regexstd/regex/regex: V ) : boolstd/core/bool: V

Does a regular expression pattern occur in a string s? (note: called test in javascript).

fun find( s : stringstd/core/string: V, regex : regexstd/regex/regex: V ) : maybestd/core/maybe: V -> V<matchedstd/regex/matched: V>

Find a match for a regular expression. See also contains (note: this fun is called |exec| in JavaScript).

fun find-all( s : stringstd/core/string: V, regex : regexstd/regex/regex: V ) : vectorstd/core/vector: V -> V<matchedstd/regex/matched: V>

Find all matches for a regular expression in a string.

fun replace( s : stringstd/core/string: V, regex : regexstd/regex/regex: V, repl : (matched : matchedstd/regex/matched: V) -> e stringstd/core/string: V ) : e stringstd/core/string: V

Replace the first occurrence of regex by the result of the replacement fun repl in a string s.

fun replace-all( s : stringstd/core/string: V, regex : regexstd/regex/regex: V, repl : (matched : matchedstd/regex/matched: V) -> e stringstd/core/string: V ) : e stringstd/core/string: V

Replace the all occurrences of regex by the result of the replacement fun repl in a string s.

fun replace-all( s : stringstd/core/string: V, regex : regexstd/regex/regex: V, repl : stringstd/core/string: V ) : stringstd/core/string: V

Replace all ocurrences of regex by the result of a replacement string repl in a string s.

fun replace( s : stringstd/core/string: V, regex : regexstd/regex/regex: V, repl : stringstd/core/string: V ) : stringstd/core/string: V

Replace the first occurrence of regex by the result a replacement string repl in a string s. The replacement string can contain $$ for a $ sign, $n for a capture group, $& for the entire match (==$0).

fun split( s : stringstd/core/string: V, r : regexstd/regex/regex: V, n : ?intstd/core/int: V ) : vectorstd/core/vector: V -> V<stringstd/core/string: V>

Split a string s in at most n parts using a regular expression r as separator.

fun split-exclude( s : stringstd/core/string: V, sep : regexstd/regex/regex: V, exclude : regexstd/regex/regex: V ) : liststd/core/list: V -> V<stringstd/core/string: V>

Split a string s over separator sep where sep does not occur in tokens matching exclude. For example: split-exclude(“comma,'sep,arated',values”, regex(“,”),regex(“‘[^’]*‘|[^’,]”)).