regular expressions for MoonBit

Find the
signal in the
noise.

Three grammars, one syntax tree, one executor. Python's re, the regex superset, and the ECMA-262 that a JSON Schema means — with the same answers on every backend.

native · wasm · wasm-gc · js  /  no dependencies  /  Apache-2.0

moonregex · live matcher

This box runs your browser's engine, so the page stays static. The showcase runs moonregex itself — type your own pattern over there.

what it does

One engine, many dialects.

A pattern is read by the grammar it was written in, lowered into one tree, and run by one backtracking machine — so switching grammars does not mean rewriting patterns.

01

Three grammars

Python's re, ECMA-262, and the lexmatch grammar the core library speaks. Named groups read as (?P<n>…), (?<n>…) and (?'n'…).

python · ecma262 · lexmatch
02

The hard parts

Backreferences, variable-length lookbehind, conditionals, recursion, atomic groups and possessive quantifiers — read, lowered, and executed.

(?(1)x|y) · (?>…) · (?R)
03

Fuzzy matching

A bounded edit budget over a literal run: {e<=1}, {i<=1}, {d<=1}, {s<=1}, and the weighted form. The spent budget is reported on the match.

approximate search
04

Shell globs

fnmatch, Glob and GlobSet translate *, **, ?, […] and {a,b} into patterns, with path-aware matching.

fnmatch · Glob · GlobSet
05

Unicode, from the UCD

\p{…} takes a category, script, block or binary property; \X matches one grapheme cluster; offsets count characters, not bytes. The tables come from moonucd.

\p{Script=Han} · \X
06

Next to the core engine

A pattern the core engine can run lowers onto it as a @string.Regex; the combinators are the same five; a match carries both views.

lower() · string · + · | · repeat
in practice

A small, honest surface.

The module functions mirror Python's re; a compiled Pattern and a Match carry the rest. Every line below is real MoonBit.

moon add moonbitstack/moonregex then moon build --target all.