The package registry is still being built. The docs are live, everything else is a preview.

Edge Python

Sign In

Sign in to publish packages and pin them by sha256.


By continuing, you accept our Terms and Conditions.

@
Palette

re (js, cli)

re is regular expressions on a backtracking engine. Declare it with edge add re and import it by bare name. To pin a different version, point the edge.json entry at another URL, 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-call step budget raises RuntimeError on catastrophic backtracking instead of hanging, and a match that recurses past the stack allowance raises the same error instead of overflowing the stack. compile and the module-level functions share one compiled-pattern cache, so a hot loop parses each pattern once.

cmd + enter
12-34
a_b_c
['one', 'two', 'three']
Output

groups and span give the captures and the offsets, and fullmatch returns None when the whole string does not match:

cmd + enter
['ada', 'edge']
[4, 6]
123
None
Output

sub expands backreferences, and flags go inline:

cmd + enter
last first
in [2024]
edge
Output

compile returns a pattern object with the same operations as methods:

cmd + enter
['one', 'two']
# # #
Output