re is regular expressions on a backtracking engine. Import it by bare name, both runtimes resolve it with no manifest. To pin a different version, import it by URL or through a packages.json alias, see Modules.
Functions are match, search, fullmatch, findall, groups, span, and sub, all taking (pattern, string). compile(pattern) returns a pattern object with the same operations as methods. Flags go inline: (?i), (?s), (?m).
The match functions return the matched string or None, there are no Match objects. groups returns the capture groups as a list, span returns [start, end] in codepoint offsets, and findall with more than one group returns a list of lists. In sub, \1 and \g<name> expand groups. The syntax covers ., Unicode-aware classes \d \w \s and their negations, sets and ranges, anchors ^ $ \b \B, quantifiers * + ? {m,n} with lazy forms, capturing, non-capturing, and named groups, backreferences \1 and (?P=name), alternation, lookahead, and fixed-width lookbehind. Not supported: Unicode property classes \p{...}, \N{...} escapes, atomic groups, possessive quantifiers, conditionals, and scoped flags (?i:...). Invalid patterns raise ValueError. A per-match step budget raises RuntimeError on catastrophic backtracking instead of hanging. compile and the module-level functions share one compiled-pattern cache, so a hot loop parses each pattern once.
12-34
a_b_c
['one', 'two', 'three']groups and span give the captures and the offsets, and fullmatch returns None when the whole string does not match:
['ada', 'edge']
[4, 6]
123
Nonesub expands backreferences, and flags go inline:
last first
in [2024]
edgecompile returns a pattern object with the same operations as methods:
['one', 'two']
# # #