Skip to content
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#

Luau
regex:Match(text: string): string?

Parameters#

ParameterTypeDescription
textstringText 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

Luau
local pattern = Regex.new("[0-9]+")
print(pattern:Match("age 25, room 7")) -- 25
print(pattern:Match("no digits")) -- nil