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(index : intstd/core/int: Vnext : intstd/core/int: Vmatched : stringstd/core/string: Vgroups : groupsstd/regex/groups: V)

The result of a regular expression match, where indexstd/regex/index: (matched : matched) -> int is the index in the original source string where the match begins, next is the index just after this match (next == index + min(1,matched.length)), matched is the content that was matched, and groups is a vector that contains the content for each capture group (where groups[0] == matched).

Automatically generated. Retrieves the indexstd/regex/index: (matched : matched) -> int constructor field of the matchedstd/regex/matched: V type.

Automatically generated. Retrieves the matched 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, start : ?intstd/core/int: 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, start : ?intstd/core/int: V ) : maybestd/core/maybe: V -> V<matchedstd/regex/matched: V>

Find a match for a regular expression starting at start position start (by default 0). See also contains (note: this fun is called |exec| in JavaScript).

fun find-all( s : stringstd/core/string: V, regex : regexstd/regex/regex: V, start : ?intstd/core/int: 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, start : ?intstd/core/int: 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, start : ?intstd/core/int: 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, start : ?intstd/core/int: 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, start : ?intstd/core/int: 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, start : ?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: splitExclude(“comma,'sep,arated',values”, regex(“,”),regex(“‘[^’]*‘|[^’,]”)).