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.
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.
| Parameter | Type | Description |
|---|---|---|
contents | string | Text 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
Luau
local numbers = Regex.new("[0-9]+")
for _, number in ipairs(numbers:MatchMany("x=12, y=34")) do
print(number) -- 12, then 34
end