interegular

0.3.3 · active · verified Thu Apr 09

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]

Warnings

Install

Imports

Quickstart

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]

from interegular import compare_regexes

# Example 1: Simple intersection
regexes1 = [r"a+", r"a*b"]
intersections1 = list(compare_regexes(*regexes1))
print(f"Intersections for {regexes1}: {intersections1}")

# Example 2: No intersection
regexes2 = [r"[0-9]+", r"[a-zA-Z]+"]
intersections2 = list(compare_regexes(*regexes2))
print(f"Intersections for {regexes2}: {intersections2}")

# Example 3: More complex patterns
regexes3 = [r"foo(bar|baz)+", r"foobar+"]
intersections3 = list(compare_regexes(*regexes3))
print(f"Intersections for {regexes3}: {intersections3}")

# You can also work with Pattern objects directly
from interegular import parse_pattern, compare_patterns

pattern_a = parse_pattern(r"A.*Z")
pattern_b = parse_pattern(r"A[0-9]+Z")

pattern_intersections = list(compare_patterns(pattern_a, pattern_b))
print(f"Pattern intersections: {pattern_intersections}")

view raw JSON →