Regular expressionsReference
Regex:Match
Return the first matching substring.
Details#
Return the first matching substring. The full first match, or nil. Capture groups are not returned separately; regex evaluation errors raise an error.
Signature#
regex:Match(text: string): string?Parameters#
| Parameter | Type | Description |
|---|---|---|
text | string | Text searched by an object created with Regex.new. |
Returns#
The full first match, or nil. Capture groups are not returned separately; regex evaluation errors raise an error.
Examples#
Local example
local pattern = Regex.new("[0-9]+")
print(pattern:Match("age 25, room 7")) -- 25
print(pattern:Match("no digits")) -- nil