A compiled regular expression pattern.
@eryx/regex Module
JSON
PCRE2-based regular expression module. Supports Perl-compatible regex with compilation, matching, searching, replacement, and splitting.
Flags string characters:
i= case-insensitivem= multiline (^ and $ match line boundaries)s= dotall (. matches newlines)x= extended (ignore whitespace and # comments in pattern)u= UTF-8 modeU= ungreedy (swap greediness of quantifiers)n= no auto capture (plain parentheses don't capture)
Summary
Classes
Functions
API Reference
Classes
Regex
Properties
Regex:isMatch
Test if the subject matches this pattern.
Parameters
the string to test
1-based start position (default 1)
Returns
boolean
Regex:find
Find the first match of this pattern in the subject. Returns nil if no match. The result table contains:
match: the full matched textstart: 1-based start positionfinish: 1-based end position (inclusive)[1],[2], ...: numbered capture groups- named fields for named capture groups
Parameters
the string to search
1-based start position (default 1)
Returns
MatchResult?
Regex:findAll
Find all non-overlapping matches in the subject.
Parameters
the string to search
Returns
{MatchResult}
Regex:replace
Replace matches in the subject with a replacement string.
The replacement supports $0 (full match), $1, ${name} backreferences.
Parameters
the input string
the replacement template
max replacements (0 or nil = replace all)
Returns
string
Regex:split
Split the subject on matches of this pattern. If the pattern has captures, captured groups are included between splits.
Parameters
the string to split
max number of pieces (0 or nil = no limit)
Returns
{string}
Regex:captureCount
Return the number of capture groups in the pattern.
Returns
number
Regex:namedCaptures
Return a table mapping named capture group names to their group numbers.
Returns
{[string]: number}
Functions
regex.new
Compile a regex pattern into a reusable Regex object.
Parameters
the PCRE2 regular expression
flag characters: i, m, s, x, u, U, n
Returns
Regex
regex.isMatch
Test if a pattern matches a subject. Convenience function that
compiles the pattern each call; use regex.new() for repeated use.
Parameters
the PCRE2 regular expression
the string to test
flag characters
Returns
boolean
regex.find
Find the first match of a pattern in a subject.
Parameters
the PCRE2 regular expression
the string to search
flag characters
Returns
MatchResult?
regex.findAll
Find all non-overlapping matches of a pattern in a subject.
Parameters
the PCRE2 regular expression
the string to search
flag characters
Returns
{MatchResult}
regex.replace
Replace all matches of a pattern in a subject.
Replacement supports $0, $1, ${name} backreferences.
Parameters
the PCRE2 regular expression
the input string
the replacement template
flag characters
Returns
string
regex.split
Split a subject on all matches of a pattern.
Parameters
the PCRE2 regular expression
the string to split
flag characters
Returns
{string}
regex.escape
Escape all PCRE2 metacharacters in a string so it can be used as a literal pattern.
Parameters
the string to escape
Returns
string
Types
MatchResult
Result of a regex match operation.