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.10
603 stars
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 →
69 /100 Good
Development Activity 80
Maintenance 44
Community 64
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
76 /100 Good
Architecture 80
Code Quality 72
Innovation 78
Learning Curve 75

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 13 apps in this directory

Go
55%
Apache 2.0

Authgear

Authentication

2,074

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
Go 55%
HTML 24%
TypeScript 18%
Updated 2 weeks ago
Python
66%
Other

AutoGPT

AI Assistants · Automation · Productivity

187,596

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
Python 66%
TypeScript 33%
Updated 1 weeks ago
Python
68%
Other

Baserow

Databases · No Code Platforms

6,012

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
Python 68%
JavaScript 16%
Vue 11%
Updated 1 weeks ago
Python
70%
Apache 2.0

GPT Researcher

AI Assistants · Productivity

29,650

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
91
Repo Health
91
Technical
63
Dependency
Built with
Python 70%
TypeScript 18%
Updated 1 weeks ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

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
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 3 weeks ago
Python
86%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,541

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

View details
82
Repo Health
75
Technical
66
Dependency
Built with
Python 86%
HTML 14%
Updated 2 weeks ago
Python
62%
Apache 2.0

marimo

Data Engineering · Developer Tools

22,918

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
89
Repo Health
91
Technical
65
Dependency
Built with
Python 62%
TypeScript 37%
Updated 1 weeks ago
Python
63%
GPL 3.0

Paperless-ngx

Bookmarks Archiving

46,108

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
Python 63%
TypeScript 28%
Updated 1 weeks ago
Python
99%
Apache 2.0

Rasa Open Source

AI Assistants · AI Development · Voice AI

21,332

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
64
Repo Health
78
Technical
63
Dependency
Built with
Python 99%
Updated 2 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