Regex object
Methods and result tables produced by Regex.new.
Methods
| Member | Type / signature | Meaning |
|---|---|---|
match | match(subject: string): {{string}} | Returns all found matches as a list of result rows. |
search | search(subject: string): {string}? | Returns the first match row, or nil. |
replace | replace(subject: string, replacement: string): string | Replaces matched spans with a literal replacement string. |
Match rows
Index 1 is the complete match. Subsequent indices contain captured groups in order. Unmatched captures can leave holes. The result is not a Luau string.match return tuple. Replacement text is inserted literally; do not assume capture substitutions such as $1 or %1.
local regex = Regex.new("([0-9]+)")
local first = regex:search("item 42")
if first then print(first[1], first[2]) end
print(regex:replace("item 42", "number"))Objects can become invalid when the 1,024-object pool retires old entries or the game world changes. The bundled engine defines pattern syntax; it is not a promise of PCRE or JavaScript regex compatibility.
