Simple regular expression matcher.
|void||clear ( )|
|int||compile ( String pattern, int capture=9 )|
|int||find ( String text, int start=0, int end=-1 ) const|
|String||get_capture ( int capture ) const|
|int||get_capture_count ( ) const|
|int||get_capture_start ( int capture ) const|
|StringArray||get_captures ( ) const|
|bool||is_valid ( ) const|
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 pattern before it can be used. The pattern must be escaped first for gdscript before it is escaped for the expression. For example:
var exp = RegEx.new()
would be read by RegEx as
would be read as
Currently supported features:
() and non-capturing
* Any character
* Shorthand character classes
\w \W \s \S \d \D
* User-defined character classes such as
* Simple quantifiers
* Range quantifiers
* Lazy (non-greedy) quantifiers
^ and end
* POSIX character classes
(?!) and lookbehind
\xFF and Unicode
\uFFFF code points (in a style similar to Python)
* Word boundaries
Member Function Description¶
- void clear ( )
This method resets the state of the object, as it was freshly created. Namely, it unassigns the regular expression of this object, and forgets all captures made by the last find.
Compiles and assign the regular expression pattern to use. The limit on the number of capturing groups can be specified or made unlimited if negative.
This method tries to find the pattern within the string, and returns the position where it was found. It also stores any capturing group (see get_capture) for further retrieval.
Returns a captured group. A captured group is the part of a string that matches a part of the pattern delimited by parentheses (unless they are non-capturing parentheses (?:)).
- int get_capture_count ( ) const
Returns the number of capturing groups. A captured group is the part of a string that matches a part of the pattern delimited by parentheses (unless they are non-capturing parentheses (?:)).
- StringArray get_captures ( ) const
Return a list of all the captures made by the regular expression.
- bool is_valid ( ) const
Returns whether this object has a valid regular expression assigned.