Regex
Library of functions for regular expressions.
Functions
FirstMatchIn
Finds the first match of a regular expression in a string.
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.
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.
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.
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.
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.
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.
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.
Regex.Replace("Heelloo John", "[aeiou]+", "_")
// Result:
// "H_ll__ J_hn"
Details
For more information about regex patterns see the Regex patterns documentation.