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.

Returns
  • string: The first match of the regular expression in the string, or null if no match is found.
Example:
Regex.FirstMatch("1234", "\\d+")
// Result:
// "1234"

Regex.FirstMatch("abc 1234", "\\d+")
// Result:
// "1234"

Regex.FirstMatch("abc", "\\d+")
// Result:
// 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.

Returns
  • list(string): The list of capturing groups of the regular expression in the string, or null if no match is found.
Example:
Regex.Groups("23-06-1975", "(\\d+)-(\\d+)-(\\d+)")
// Result:
// ["23", "06", "1975"]

Regex.Groups("23-06", "(\\d+)-(\\d+)-(\\d+)?")
// Result:
// ["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.

Returns
  • bool: True if the pattern matches, false otherwise.
Example:
Regex.Matches("1234", "\\d+")
// Result:
// true

Regex.Matches("abc 1234", "\\d+")
// Result:
// 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.

Returns
  • string: The string with the replaced matches.
Example:
Regex.Replace("Heelloo John", "[aeiou]+", "_")
// Result:
// "H_ll__ J_hn"

Details

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