ReferenceMiscellaneous

Regex.new

Compiles a regular expression.

Syntax

Regex.new(pattern: string) -> Regex

Also available as

Regex

Parameters

ParameterTypeDescription
patternstringPattern text.

Returns

TypeDescription
RegexA compiled pattern with :Match(text) and :Replace(text, replacement).

Description

Supports literals, ., character classes with ranges and negation, \d \w \s and their capitals, ^ and $, groups, non-capturing (?:...), alternation |, and the quantifiers * + ? {n,m} with lazy forms. :Match returns a table with Captures (whole match first, then each group), Start and End, or nil. :Replace replaces every match with the given plain text. A malformed pattern such as an unclosed group raises an error.

Example

local match = Regex.new("d(e+)b"):Match("xdeeeb")
print(match.Captures[1], match.Captures[2])

These are Game executor contracts. Check build requirements and session lifetimes before using them.