{"id":2075,"library":"interegular","title":"interegular","description":"Interegular is a Python library designed to check a subset of Python regular expressions for intersections. Currently at version 0.3.3, it focuses on speed and compatibility with Python's `re` module syntax, differentiating itself from libraries like `greenery` by prioritizing performance over regex reconstruction from Finite State Machines (FSMs). The project appears to have an active development status, with updates released on an irregular cadence. [1, 2, 3]","status":"active","version":"0.3.3","language":"python","source_language":"en","source_url":"https://github.com/MegaIng/regex_intersections","tags":["regex","regular expressions","intersection","fsm","finite state machine","lark-parser"],"install":[{"cmd":"pip install interegular","lang":"bash","label":"Install `interegular`"}],"dependencies":[{"reason":"The library is adapted for and relies on `lark-parser` for its backend, particularly for parsing regex patterns.","package":"lark","optional":false}],"imports":[{"symbol":"compare_regexes","correct":"from interegular import compare_regexes"},{"symbol":"parse_pattern","correct":"from interegular import parse_pattern"},{"symbol":"Pattern","correct":"from interegular import Pattern"},{"symbol":"REFlags","correct":"from interegular import REFlags"},{"symbol":"FSM","correct":"from interegular import FSM"},{"symbol":"Comparator","correct":"from interegular import Comparator"}],"quickstart":{"code":"from interegular import compare_regexes\n\n# Example 1: Simple intersection\nregexes1 = [r\"a+\", r\"a*b\"]\nintersections1 = list(compare_regexes(*regexes1))\nprint(f\"Intersections for {regexes1}: {intersections1}\")\n\n# Example 2: No intersection\nregexes2 = [r\"[0-9]+\", r\"[a-zA-Z]+\"]\nintersections2 = list(compare_regexes(*regexes2))\nprint(f\"Intersections for {regexes2}: {intersections2}\")\n\n# Example 3: More complex patterns\nregexes3 = [r\"foo(bar|baz)+\", r\"foobar+\"]\nintersections3 = list(compare_regexes(*regexes3))\nprint(f\"Intersections for {regexes3}: {intersections3}\")\n\n# You can also work with Pattern objects directly\nfrom interegular import parse_pattern, compare_patterns\n\npattern_a = parse_pattern(r\"A.*Z\")\npattern_b = parse_pattern(r\"A[0-9]+Z\")\n\npattern_intersections = list(compare_patterns(pattern_a, pattern_b))\nprint(f\"Pattern intersections: {pattern_intersections}\")","lang":"python","description":"This quickstart demonstrates how to use `interegular.compare_regexes` to find intersections between multiple regular expression strings and `compare_patterns` for pre-parsed `Pattern` objects. It shows cases with and without common matches. [1, 2, 3]"},"warnings":[{"fix":"Avoid using unsupported regex features. Test complex patterns thoroughly to ensure correct behavior. Consider simplifying regexes if unexpected results occur.","message":"The library does not support all Python `re` features due to its FSM backend. Specifically, it lacks support for backwards references (e.g., `\\1`, `(?P=name)`) and conditional matching (e.g., `(?(1)a|b)`). Some complex lookaheads/lookbacks may also not work correctly, potentially parsing but yielding incorrect results. [1, 2, 3]","severity":"gotcha","affected_versions":"All versions"},{"fix":"Check the `REFlags` enum for supported flags. If a crucial flag is missing, you might need to preprocess your regex or adjust your logic to not depend on that flag.","message":"Not all `re` flags are currently implemented. The documentation specifically mentions 'ims' (from `aiLmsux`) as being in progress. If your regexes rely on specific flags, verify their support. [1, 2, 3]","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your `lark` parser configuration, if used directly, specifies a `basic` or `contextual` lexer for compatibility with `interegular`.","message":"`interegular` is designed to work with the `lark` parser, but its functionality is currently limited to when the lexer in `lark` is set to `basic` or `contextual`. Using other lexer types might lead to unexpected behavior or errors. [8]","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware that lazy quantifiers will behave greedily. Adjust your regexes to achieve the desired effect without relying on non-greedy semantics, or accept the greedy interpretation when using `interegular`.","message":"Lazy quantifiers (e.g., `*?`, `+?`, `??`) are currently treated the same way as their greedy counterparts (`*`, `+`, `?`). This can lead to surprising behavior and incorrect intersection results if your regex logic relies on non-greedy matching. [18]","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.3.3':21 '1':67 '2':68 '3':69 'activ':57 'appear':53 'cadenc':66 'check':9 'compat':27 'current':18 'design':7 'develop':58 'differenti':34 'express':15,72 'finit':47,75 'focus':23 'fsm':74 'fsms':50 'greeneri':39 'interegular':1,2 'intersect':17,73 'irregular':65 'lark':79 'lark-pars':78 'librari':6,37 'like':38 'machin':49,77 'modul':32 'parser':80 'perform':42 'priorit':41 'project':52 'python':5,13,29 're':31 'reconstruct':45 'regex':44,70 'regular':14,71 'releas':62 'speed':25 'state':48,76 'status':59 'subset':11 'syntax':33 'updat':61 'version':20","created_at":"2026-04-09T18:42:27.582653+00:00","updated_at":"2026-04-16T15:46:14.169973+00:00","problems":[{"fix":"Simplify the regular expression by removing or rewriting unsupported constructs. Consult the `interegular` documentation for supported regex syntax.","cause":"The `interegular` library does not support all features of Python's `re` module, particularly certain escape sequences (like `\\b` for word boundaries), backreferences, conditional matching, and some lookaheads/lookbacks, due to its FSM-based backend.","error":"interegular.patterns.Unsupported: Escape \\b is not implemented"},{"fix":"Simplify the regular expression, break down complex patterns into smaller, manageable parts, or redesign the logic to avoid overly complex regexes that generate excessively large FSMs.","cause":"Complex or very long regular expressions can lead to the generation of extremely large Finite State Machines (FSMs), causing `interegular.parse_pattern().to_fsm()` and `FSM.reduce()` operations to be very slow and consume significant memory, potentially making the application unresponsive.","error":"interegular parse_pattern().to_fsm() very slow / application freezing"},{"fix":"Avoid using case-insensitive flags with problematic Unicode characters or manually handle the case sensitivity for such characters within your regex if possible. A specific fix for this issue might require a patched version of the library as indicated in some discussions.","cause":"When using case-insensitive regular expressions (`(?i:...)`) with certain Unicode characters (e.g., `ß`, `İ`), `interegular` can encounter an `AssertionError`. This happens because internal logic assumes that `str.upper()` or `str.lower()` operations on a single character will always result in a single-character string, which is not true for all Unicode characters.","error":"AssertionError in make_byte_level_fsm (or similar related to case-insensitive regex)"},{"fix":"Carefully review the regular expression string for any syntax errors, unclosed groups, or unsupported features. Ensure the regex strictly adheres to the subset of Python `re` syntax that `interegular` is designed to handle.","cause":"This error occurs when `interegular`'s internal parser cannot successfully parse the provided regular expression string at a specific index, indicating a syntax error, a malformed regex, or an unsupported pattern that the parser fails to recognize.","error":"interegular.utils.simple_parser.NoMatch: Can not match at index X. Got '...'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.3.3","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/MegaIng/interegular","docs":null,"changelog":null,"pypi":"https://pypi.org/project/interegular/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}