Skip to main content

Regex

Library of functions for regular expressions.

Functions

FirstMatchIn

Finds the first match of a regular expression in a string.

Syntax:
Regex.FirstMatchIn(string: string, pattern: string)
Parameters
  • string: The string to analyze.
  • pattern: The regular expression to match.
Example:
Regex.FirstMatch("1234", "\\d+") "123"
Regex.FirstMatch("abc 1234", "\\d+") // "1234"
Regex.FirstMatch("abc", "\\d+") // null

Details

For more information about regex patterns see the Regex patterns documentation.

Groups

Finds the list of capturing groups of a regular expression in a string.

Syntax:
Regex.Groups(string: string, pattern: string)
Parameters
  • string: The string to analyze.
  • pattern: The regular expression to match.
Example:
Regex.Groups("23-06-1975", "(\\d+)-(\\d+)-(\\d+)") // ["23", "06", "1975"]
Regex.Groups("23-06", "(\\d+)-(\\d+)-(\\d+)?") // ["23", "06", null]

Details

For more information about regex patterns see the Regex patterns documentation.

Matches

Checks if a string matches a regular expression pattern.

Syntax:
Regex.Matches(string: string, pattern: string)
Parameters
  • string: The string to analyzer.
  • pattern: The regular expression to match.
Example:
"Regex.Matches("1234", "\\d+") // true
Regex.Matches("abc 1234", "\\d+") // false

Details

For more information about regex patterns see the Regex patterns documentation.

Replace

Replaces matches of a regular expression pattern by a new string.

Syntax:
Regex.Replace(string: string, pattern: string, newSubString: string)
Parameters
  • string: The string to be analyzed.
  • pattern: The regular expression pattern to match.
  • newSubString: The new substring to replace matches with.
Example:
Regex.Replace("Heelloo John", "[aeiou]+", "_") // "H_ll_ J_hn"

Details

For more information about regex patterns see the Regex patterns documentation.