interegular
a regex intersection checker
What it is and what it does
Interegular is a library for detecting whether pairs of Python regular expressions can match overlapping input strings. It parses regex patterns into finite-state machines (FSMs) and compares them to find intersections, returning pairs of patterns that overlap. The library is adapted from grennery but optimized for speed and compatibility with Python's re module syntax.
The package exposes a high-level API (compare_regexes) for quick intersection checks and lower-level Pattern and FSM classes for more detailed analysis. It supports most common regex syntax but explicitly does not handle backreferences, conditional matching, or all lookahead/lookbehind cases—these limitations are inherent to the FSM-based approach. It is useful in parser generators, validation rule analysis, and regex conflict detection.
Use it for:
- Detect conflicting patterns in a parser or lexer to warn about ambiguous token definitions.
- Validate that two regex-based validation rules do not overlap in unexpected ways.
- Analyze a set of URL routing patterns to find potential collisions.
- Check whether input sanitization regexes and attack patterns intersect.
- Test regex-based firewall or IDS rules for unintended overlaps.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Interegular checks whether pairs of Python regular expressions can match overlapping strings, converting regex patterns to finite-state machines to detect intersections.
Yes, if you need to detect regex intersections and can work within its constraints. The library is lightweight, has no dependencies, and works on current Python versions. Dormant maintenance is a minor concern but not a blocker for a stable utility. Avoid it if your patterns rely heavily on backreferences, conditionals, or complex lookaheads.
Install
interegular on PyPI
pip
pip install interegularuv
uv add interegularpoetry
poetry add interegularInstalling interegular
Before you install
Low friction installation with no runtime dependencies. Maintenance is dormant—last release was 2024-01-06, but the repository remains active and the package supports current Python versions (3.8–3.12).
License in practice
MIT license permits commercial and private use with minimal restrictions, requiring only attribution and inclusion of the license text.
Quickstart
pip install interegular
from interegular import compare_regexes
for pattern_a, pattern_b in compare_regexes(r'a+', r'a*b'):
print(f'Intersection: {pattern_a}, {pattern_b}')
Requires Python 3.7 or later. Some regex features (backreferences, conditional matching, certain lookaheads/lookbacks) are not supported.
Verify before relying
- Correctness of lookahead/lookbehind handling—documentation notes this is not correctly handled in all cases.
- Performance characteristics when comparing large numbers of complex patterns.
- Completeness of flag support (only i, m, s implemented from aiLmsux).
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 951 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 5,193,419/month — #2,144 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: interegular-0.3.3-py37-none-any.whl
Tags
More Text Processing packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyparsingpyparsing provides a library for building text…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
RapidFuzzRapidFuzz provides fast fuzzy string matching…
permissive · top 1,000 on PyPI
tinycss2tinycss2 parses CSS strings into token and…
permissive · top 1,000 on PyPI
llama-parseLlamaParse parses complex documents (PDFs,…
permissive · top 1,000 on PyPI
greeneryParses and manipulates regular expressions by…
permissive · top 15,000 on PyPI
multiregexMatches multiple regex patterns against a…
permissive · top 15,000 on PyPI
regexploitRegexploit analyzes regular expressions to…
permissive · top 15,000 on PyPI
rebulkReBulk provides a fluent API for building…
permissive · top 15,000 on PyPI
onigurumacffiProvides Python bindings to the Oniguruma regex…
permissive · top 15,000 on PyPI
re-assertProvides a helper class for regex assertions…
permissive · top 15,000 on PyPI
hyperscanPython bindings for Vectorscan (an open-source…
permissive · top 15,000 on PyPI
flpcflpc wraps the Rust regex crate to provide…
permissive · top 5,000 on PyPI
slotscheckValidates that `__slots__` are correctly…
permissive · top 15,000 on PyPI