regex.match

Finds the first PCRE2 match in Text.

Syntax

Signature
regex.match(Text: string, Pattern: string) -> table?

Aliases

This function has no aliases.

Parameters

ParameterTypeDescription
TextstringInput bytes, up to 1 MiB.
PatternstringPCRE2 pattern, up to 16 KiB. UTF mode is not enabled.

Returns

TypeDescription
table?Match strings with Start and End byte offsets, or nil.

Notes

Index 1 contains the full match and later indexes contain reported capture groups. Reported unmatched captures are false. Start is the one-based starting byte and End is the inclusive ending byte. Returns nil when no match is found. Invalid patterns and matching-limit failures raise errors.

Example

Luau
local Match = regex.match("score=125", "score=([0-9]+)")
if Match then print(Match[2], Match.Start, Match.End) end