Regex:Match Synchronous

Find the first substring that satisfies this compiled pattern. Use it when you want one hit, or pair it with anchors to validate a complete input.

Syntax
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.

Function parameters
ParameterTypeDescription
contentsstringText to search.

Returns

string?

The full matching substring, or nil when nothing matches. Capture groups are not returned separately.

Usage notes

For every hit, use MatchMany. A successful result may be shorter than the input unless the pattern is anchored.

Example

Example
Luau
local ticket = Regex.new("[A-Z]+-[0-9]+")
local id = ticket:Match("Please check BUG-104 today")
if id then print(id) end -- BUG-104
Kawaii documentation