mrab-regex

A backwards-compatible drop-in replacement for Python's re module, adding fuzzy matching, nested sets, recursive patterns, and full Unicode case-folding.

Library
PyPI
v2026.9.3
598stars
Apache-2.0 AND CNRI-Python

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
65/100Good
Development Activity76
Maintenance36
Community60
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture80
Code Quality72
Innovation78
Learning Curve75

regex is a mature alternative to Python’s built-in re module, maintained as a superset that stays backwards-compatible while extending what the standard library can do. Under the covers it’s a C extension (the bulk of the codebase is C, not Python) wrapped by a thin Python front-end, which is why it keeps pace with re’s performance while adding features CPython has never shipped.

The headline additions are approximate (“fuzzy”) matching with configurable insertion/substitution/deletion budgets, nested character sets with set algebra (union, intersection, difference), recursive and named-group back-references, variable-length lookbehind, and both simple and full Unicode case-folding. A VERSION0/VERSION1 flag lets callers pin the old re-compatible behavior or opt into the newer, corrected semantics (e.g. properly handled zero-width matches) without breaking existing code.

Because it mirrors the re API almost exactly, most projects adopt it with a single import swap (import regex as re), then progressively opt into the extended syntax where it earns its keep — log scrubbing and OCR text cleanup with fuzzy matching, Unicode-aware tokenization, or patterns too intricate for re’s more limited grammar.

What You Get

  • A near drop-in replacement for re — most code migrates with a single import change
  • Approximate/fuzzy matching with explicit limits on substitutions, insertions, and deletions per match
  • Nested character sets with set operators (union ||, intersection &&, difference --)
  • Recursive patterns ((?R), (?1), (?&name)) for matching balanced or self-referential structures
  • Variable-length lookbehind assertions, unlike re’s fixed-width-only lookbehind
  • Full Unicode case-folding in addition to re’s simple case-folding
  • VERSION0/VERSION1 flags to choose between re-compatible and corrected/enhanced behavior explicitly

Common Use Cases

  • Migrating existing re-based code to gain performance or bug fixes with minimal changes
  • Fuzzy-matching noisy text such as OCR output, user-entered data, or log lines with typos
  • Parsing nested or balanced constructs (brackets, tags) via recursive group references
  • Unicode-heavy text processing that needs full case-folding across scripts
  • Building tokenizers or validators that need set algebra inside character classes

Under The Hood

Architecture The project is a thin-Python-over-C design: regex/_main.py and regex/_regex_core.py implement pattern compilation, flag handling, and the public API surface (compile, match, search, sub, split, and friends), while the actual matching engine lives in src/_regex.c and src/_regex_unicode.c — together over 26,000 lines of C, roughly 86% of the codebase by bytes. Python owns parsing and orchestration; C owns the hot-path matching loop, which is what lets fuzzy and recursive matching run at competitive speed instead of falling back to a pure-Python backtracker.

Tech Stack Built with setuptools (pyproject.toml + setup.py) compiling a single C extension module (regex._regex) against src/_regex.c and src/_regex_unicode.c, with a Py_GIL_DISABLED macro path for free-threaded CPython builds. No runtime dependencies — it targets CPython specifically (the README notes it doesn’t behave correctly on PyPy due to string-representation differences) and supports Python 3.10 through the upcoming 3.15 line per its classifiers.

Code Quality Testing runs through the standard-library unittest framework against a single large suite (regex/tests/test_regex.py, ~4,500 lines) exercising both VERSION0 and VERSION1 behavior paths, and CI (cibuildwheel GitHub Actions workflow) runs that suite across Ubuntu, macOS, and Windows for every tagged release, plus builds and tests wheels for CPython 3.10 through 3.15 (including free-threaded variants). There’s no separate linter/formatter configuration checked in, and as a C-extension project it doesn’t use Python type hints, but the extensive single-file test suite and multi-platform wheel-build matrix substitute for that kind of tooling.

What Makes It Unique What sets regex apart from re and from most other regex engines is that it doesn’t trade off compatibility for features — it defaults to re-identical behavior (VERSION0) and only exposes fuzzy matching, nested sets, and recursive patterns when a caller opts in via flags or syntax, so existing re patterns keep working unchanged. The fuzzy-matching implementation in particular — configurable per-error-type budgets with BESTMATCH/ENHANCEMATCH refinement flags and introspectable fuzzy_counts/fuzzy_changes results — goes well beyond what most “approximate matching” libraries expose, since it stays exposed through the same compiled-pattern API as ordinary matching.

Used by 12 apps in this directory

Go
54%
Apache 2.0

Authgear

Authentication

2,028

Open-source, self-hostable authentication platform with passkeys, biometric login, SSO, MFA, and GraphQL admin API — a full Auth0/Clerk/Firebase alternative for SaaS and mobile apps.

View details
88
Repo Health
81
Technical
68
Dependency
Built with
Go54%
HTML25%
TypeScript18%
Updated 3 days ago
Python
67%
Other

AutoGPT

Automation · Productivity · AI Assistants

187,177

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
66
Dependency
Built with
Python67%
TypeScript32%
Updated today
Python
68%
Other

Baserow

No Code Platforms · Databases

5,830

Open-source no-code platform to build databases, apps, automations, and AI agents — self-hosted or cloud, with full data ownership.

View details
89
Repo Health
84
Technical
68
Dependency
Built with
Python68%
JavaScript16%
Vue12%
Updated yesterday
Python
67%
Apache 2.0

GPT Researcher

Productivity · AI Assistants

29,319

The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.

View details
90
Repo Health
91
Technical
63
Dependency
Built with
Python67%
TypeScript20%
Updated 1 weeks ago
TypeScript
91%
Apache 2.0

Helicone

Monitoring · AI Development · Analytics

6,133

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
69
Repo Health
81
Technical
65
Dependency
Built with
TypeScript91%
Updated 1 weeks ago
Python
85%
Apache 2.0

knowhere

AI Development · Developer Tools

2,942

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
69
Dependency
Built with
Python85%
HTML15%
Updated yesterday
Python
61%
Apache 2.0

marimo

Developer Tools · Data Engineering

22,670

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
65
Dependency
Built with
Python61%
TypeScript37%
Updated yesterday
Python
62%
GPL 3.0

Paperless-ngx

Bookmarks Archiving

44,898

Turn your paper pile into a searchable digital archive with OCR, AI classification, and automated workflows — all running on your own server.

View details
91
Repo Health
88
Technical
67
Dependency
Built with
Python62%
TypeScript30%
Updated today
Python
99%
Apache 2.0

Rasa Open Source

AI Assistants · AI Development

21,315

Rasa Open Source is a Python machine learning framework for building contextual, multi-turn chatbots and voice assistants that understand natural language and maintain conversation state.

View details
65
Repo Health
78
Technical
63
Dependency
Built with
Python99%
Updated 1 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search