RegexMatch
string RegexMatch(string text, string pattern)Description
Searches text for the first occurrence of pattern and returns the matched substring.
If the pattern contains capture groups (...), the content of the first capture group is returned.
If no match is found, an empty string is returned and an info message is logged.
An invalid pattern causes a script error.
Parameter
- text - The input string to search in.
- pattern - The regular expression pattern.
Returns
The matched substring or first capture group as a string, or an empty string if no match was found.
Example
void main()
{
string m1 = RegexMatch("Version 3.14", "\\d+\\.\\d+"); // "3.14"
string m2 = RegexMatch("user@mail.com", "(\\w+)@"); // "user" (1st group)
string m3 = RegexMatch("abc", "\\d+"); // "" (no match)
}