blob: 4577672c729765a5331a636eb28d54e3f78da3de (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
<?xml version="1.0" encoding="UTF-8" ?>
<class name="RegEx" inherits="Reference" category="Core" version="3.0.alpha.custom_build">
<brief_description>
Simple regular expression matcher.
</brief_description>
<description>
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]
</description>
<tutorials>
</tutorials>
<demos>
</demos>
<methods>
<method name="clear">
<return type="void">
</return>
<description>
This method resets the state of the object, as it was freshly created. Namely, it unassigns the regular expression of this object.
</description>
</method>
<method name="compile">
<return type="int" enum="Error">
</return>
<argument index="0" name="pattern" type="String">
</argument>
<description>
Compiles and assign the search pattern to use.
</description>
</method>
<method name="get_group_count" qualifiers="const">
<return type="int">
</return>
<description>
Returns the number of numeric capturing groups.
</description>
</method>
<method name="get_names" qualifiers="const">
<return type="Array">
</return>
<description>
Returns an array of names of named capturing groups.
</description>
</method>
<method name="get_pattern" qualifiers="const">
<return type="String">
</return>
<description>
Returns the search pattern used to compile the code.
</description>
</method>
<method name="is_valid" qualifiers="const">
<return type="bool">
</return>
<description>
Returns whether this object has a valid search pattern assigned.
</description>
</method>
<method name="search" qualifiers="const">
<return type="RegExMatch">
</return>
<argument index="0" name="subject" type="String">
</argument>
<argument index="1" name="offset" type="int" default="0">
</argument>
<argument index="2" name="end" type="int" default="-1">
</argument>
<description>
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.
</description>
</method>
<method name="sub" qualifiers="const">
<return type="String">
</return>
<argument index="0" name="subject" type="String">
</argument>
<argument index="1" name="replacement" type="String">
</argument>
<argument index="2" name="all" type="bool" default="false">
</argument>
<argument index="3" name="offset" type="int" default="0">
</argument>
<argument index="4" name="end" type="int" default="-1">
</argument>
<description>
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.
</description>
</method>
</methods>
<constants>
</constants>
</class>
|