A compiled regular expression pattern.
@eryx/regex Module
PCRE2-based regular expression module. Supports Perl-compatible regex with compilation, matching, searching, replacement, and splitting.
:::note Optional capability
This module is a typed facade over an optional PCRE2 backend. In
builds without PCRE2 support, require("@eryx/regex") fails
immediately with a clear capability error.
:::
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
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
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
Returns
{string}
Regex:captureCount
Return the number of capture groups in the pattern.
Returns
number
Functions
regex.new
Compile a regex pattern into a reusable Regex object.
Parameters
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.
Constants
- Compile-time flag constants (Exact values depend on PCRE2, and are not documented here.)
regex.CASELESS=0regex.MULTILINE=0regex.DOTALL=0regex.EXTENDED=0regex.UTF=0regex.UNGREEDY=0regex.NO_AUTO_CAPTURE=0regex.ANCHORED=0regex.ENDANCHORED=0regex.UCP=0regex.DUPNAMES=0