Regex: Match Synchronous
Find the first substring that matches this regular expression. Use it to extract a first value or check that text matches an anchored pattern. Test against nil when an empty-string match is also possible.
Luau
Regex:Match(contents: string) -> string?Parameters
Call this method with a Regex receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.
| Parameter | Type | Description |
|---|---|---|
contents | string | Text to search. |
Returns
string?The full matched substring, or nil if there is no match. It does not return capture groups or a match-record object.
Example
Luau
local integer = Regex.new("^[0-9]+$")
for _, input in ipairs({ "42", "4x" }) do
print(input, integer:Match(input) ~= nil)
end -- 42: true; 4x: false