Regex:MatchMany Synchronous

Collect successive matches into one array. This works well for extracting several tokens from a short piece of text without writing a manual search loop.

Syntax
Luau
Regex:MatchMany(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 from beginning to end.

Returns

{string}

An array of full matched substrings in search order. No matches give an empty array.

Usage notes

Capture groups are not separate array elements. The compiled pattern decides which part of each match is returned.

Example

Example
Luau
local numbers = Regex.new("[0-9]+")
for _, number in ipairs(numbers:MatchMany("x=12, y=34")) do
    print(number) -- 12, then 34
end
Kawaii documentation