--- id: interegular version: "0.3.3" license: MIT license_treatment: permissive maintenance: dormant --- # interegular — a regex intersection checker License: permissive · Maintenance: dormant · Downloads: 5.2M/mo ## 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 above — 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 pip install interegular uv add interegular 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_current - Install friction: low - Maintenance: dormant - Downloads: 5.2M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags regex intersection detection, check overlapping regexes, regex pattern comparison, finite state machine regex, regex conflict detection, pattern overlap checker, regex fsm analysis, regex-analysis, fsm, pattern-matching [View on SkillFed](https://skillfed.io/packages/interegular) · [View on PyPI](https://pypi.org/project/interegular/)