This repository was archived by the owner on Nov 22, 2026. It is now read-only.
Repository navigation
uregex 0.3.0
mojo-uregex v0.3.0
Released: 2026-10-08 · Previous: first release in this repository
What it does
Unicode-aware regular expressions for Mojo, built for the pre-tokenizers of LLM
tokenizers (GPT-2, Llama 3, Qwen, DeepSeek, gpt-oss, Spark-X2.5) and checked
against Python's regex by differential testing. Pure Mojo, CPU. Build with
-I src; requires Mojo 1.1.
Highlights
- 1.9 to 3.1x faster than Python
regexon the tokenizer patterns (tools/bench.sh); slowest on plain-ASCII GPT-2 text. - Two engines from one source:
Patternfor tokenizers,FullPatternfor capture groups, named groups,\b\Band fixed-length lookbehind. - Byte offsets on UTF-8 input with no copy to codepoints; codepoint offsets on request.
- Unicode 18.0 general categories and case maps, generated from the Unicode Character Database by
tools/gen_unicode.mojoand checked against Pythonregex.
Changes
First release in this repository. Public API:
Pattern(src),FullPattern(src):findall,findall_spans,findall_cps_offsets,search,split_keep;FullPatternaddsfindall_groups,groups(),group_index(name).- One-shot helpers
findall,search,split_keep,compile(full syntax). - Supported and rejected syntax: README, "Supported syntax".
Verified
| Check | Result |
|---|---|
tools/gate.sh: unit tests, check_unicode.py (every table vs regex 2026.9.29), difftest (every pattern in tools/difftest.py x 5004 random texts, codepoint and byte offsets), negative control |
PASS: 14/14 tests, 41 tables equal, every pattern equal in both offset modes, negative control caught every pattern |
tools/bench.sh: match counts equal Python regex on every tokenizer pattern |
agree on all 6 |
Fresh clone: README setup run top to bottom in an empty directory, then tools/gate.sh |
PASS: mojo==1.1.0 and regex==2026.9.29 from PyPI, full gate green |
Known limits
- Backtracking engine: pathological patterns can be exponential.
- No backreferences, possessive quantifiers or variable-length lookbehind.
FullPatternis slower thanPatternfor the same pattern; usePatternunless you need its syntax.- Positions are Int32 internally: inputs over 2 GiB are not supported.
Upgrade / run
python3 -m venv .venv && ./.venv/bin/pip install 'mojo==1.1.0' 'regex==2026.9.29'
./.venv/bin/mojo run -I src tests/test_uregex.mojo
tools/gate.sh
Commits
uregex 0.3.0: initial public commit.