Simple regular expression matcher.
Class for finding text patterns in a string using regular expressions. It can not perform replacements. Regular expressions are a way to define patterns of text to be searched. Details on writing patterns are too long to explain here but the Internet is full of tutorials and detailed explanations.
Once created, the RegEx object needs to be compiled with the search pattern before it can be used. The search pattern must be escaped first for gdscript before it is escaped for the expression. For example:
[code]var exp = RegEx.new()[/code]
[code]exp.compile("\\d+")[/code]
would be read by RegEx as [code]\d+[/code]
Similarly:
[code]exp.compile("\"(?:\\\\.|[^\"])*\"")[/code]
would be read as [code]"(?:\\.|[^"])*"[/code]
Currently supported features:
* Capturing [code]()[/code] and non-capturing [code](?:)[/code] groups
* Named capturing groups [code](?P<name>)[/code]
* Any character [code].[/code]
* Shorthand character classes [code]\w \W \s \S \d \D[/code]
* User-defined character classes such as [code][A-Za-z][/code]
* Simple quantifiers [code]?[/code], [code]*[/code] and [code]+[/code]
* Range quantifiers [code]{x,y}[/code]
* Lazy (non-greedy) quantifiers [code]*?[/code]
* Beginning [code]^[/code] and end [code]$[/code] anchors
* Alternation [code]|[/code]
* Backreferences [code]\1[/code], [code]\g{1}[/code], and [code]\g<name>[/code]
* POSIX character classes [code][[:alnum:]][/code]
* Lookahead [code](?=)[/code], [code](?!)[/code] and lookbehind [code](?<=)[/code], [code](?<!)[/code]
* ASCII [code]\xFF[/code] and Unicode [code]\uFFFF[/code] code points (in a style similar to Python)
* Word boundaries [code]\b[/code], [code]\B[/code]
This method resets the state of the object, as it was freshly created. Namely, it unassigns the regular expression of this object.
Compiles and assign the search pattern to use.
Returns the number of numeric capturing groups.
Returns an array of names of named capturing groups.
Returns the search pattern used to compile the code.
Returns whether this object has a valid search pattern assigned.
Searches the text for the compiled pattern. Returns a [RegExMatch] container of the first matching result if found, otherwise null. The region to search within can be specified without modifying where the start and end anchor would be.
Searches the text for the compiled pattern and replaces it with the specified string. Escapes and backreferences such as [code]\1[/code] and [code]\g<name>[/code] expanded and resolved. By default only the first instance is replaced but it can be changed for all instances (global replacement). The region to search within can be specified without modifying where the start and end anchor would be.