mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 07:17:42 -05:00
Replace XML codeblock spaces with tabs
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
regex.compile("\\w-(\\d+)")
|
||||
var result = regex.search("abc n-0123")
|
||||
if result:
|
||||
print(result.get_string()) # Would print n-0123
|
||||
print(result.get_string()) # Would print n-0123
|
||||
[/codeblock]
|
||||
The results of capturing groups [code]()[/code] can be retrieved by passing the group number to the various methods in [RegExMatch]. Group 0 is the default and will always refer to the entire pattern. In the above example, calling [code]result.get_string(1)[/code] would give you [code]0123[/code].
|
||||
This version of RegEx also supports named capturing groups, and the names can be used to retrieve the results. If two or more groups have the same name, the name would only refer to the first one with a match.
|
||||
@@ -26,12 +26,12 @@
|
||||
regex.compile("d(?<digit>[0-9]+)|x(?<digit>[0-9a-f]+)")
|
||||
var result = regex.search("the number is x2f")
|
||||
if result:
|
||||
print(result.get_string("digit")) # Would print 2f
|
||||
print(result.get_string("digit")) # Would print 2f
|
||||
[/codeblock]
|
||||
If you need to process multiple results, [method search_all] generates a list of all non-overlapping results. This can be combined with a [code]for[/code] loop for convenience.
|
||||
[codeblock]
|
||||
for result in regex.search_all("d01, d03, d0c, x3f and x42"):
|
||||
print(result.get_string("digit"))
|
||||
print(result.get_string("digit"))
|
||||
# Would print 01 03 0 3f 42
|
||||
[/codeblock]
|
||||
[b]Example:[/b] Split a string using a RegEx:
|
||||
@@ -40,7 +40,7 @@
|
||||
regex.compile("\\S+") # Negated whitespace character class.
|
||||
var results = []
|
||||
for result in regex.search_all("One Two \n\tThree"):
|
||||
results.push_back(result.get_string())
|
||||
results.push_back(result.get_string())
|
||||
# The `results` array now contains "One", "Two", and "Three".
|
||||
[/codeblock]
|
||||
[b]Note:[/b] Godot's regex implementation is based on the [url=https://www.pcre.org/]PCRE2[/url] library. You can view the full pattern reference [url=https://www.pcre.org/current/doc/html/pcre2pattern.html]here[/url].
|
||||
|
||||
Reference in New Issue
Block a user