skillfed

interegular

a regex intersection checker

interegular v0.3.3 5.2M downloads/30d#2,144 on PyPI58
Permissive license MIT DORMANT released

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 interegular

uv

uv add interegular

poetry

poetry add interegular

Installing 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

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

regex intersection detectioncheck overlapping regexesregex pattern comparisonfinite state machine regexregex conflict detectionpattern overlap checkerregex fsm analysis
regex-analysisfsmpattern-matching

More Text Processing packages