--- id: greenery version: "4.2.2" license: MIT License license_treatment: permissive maintenance: aging --- # greenery — Greenery allows manipulation of regular expressions License: permissive · Maintenance: aging · Downloads: 250.5K/mo ## What it is and what it does Greenery is a library for parsing and manipulating regular expressions at the language level—not for matching strings, but for reasoning about the patterns themselves. It converts regexes to finite state machines internally, allowing you to perform set operations like intersection, union, difference, and complement on regex patterns. The core use case is computing the intersection of two regular expressions: the set of strings that both patterns accept, returned as a new regex. The library supports standard regex syntax (character classes, quantifiers, alternation, grouping) but intentionally omits anchors (^ and $), backreferences, and lookahead/lookbehind constructs, since these fall outside formal regular language theory. It provides a Pattern API with methods modeled on frozenset, plus regex-specific operations like reversal, derivation (Brzozowski derivative), and reduction (simplification heuristics). With no external dependencies and a permissive MIT license, it's lightweight and suitable for embedding in tools that need to reason about regex patterns. Use it for: - Find the common strings accepted by two regex patterns by computing their intersection. - Simplify complex regular expressions using the reduce() method to apply algebraic simplification heuristics. - Reverse a regex pattern to match reversed strings, useful in bidirectional text processing. - Test regex equivalence by comparing two patterns to verify they match exactly the same set of strings. - Generate all strings matched by a regex using the strings() generator, for validation or testing. - Compute the complement of a regex (everythingbut) to match all strings not accepted by the original pattern. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Parses and manipulates regular expressions by converting them to finite state machines, enabling operations like computing the intersection of two regexes to find strings both accept. Yes, if you need to reason about regular expressions as formal languages—computing intersections, complements, or equivalences. The library is stable, has no dependencies, and carries a permissive license. However, it is aging (no release since 2024-06-08); install it for a specific regex-algebra task, but do not expect active maintenance or rapid updates. ## Install pip install greenery uv add greenery poetry add greenery ## Installing greenery Before you install: Low install friction with no runtime dependencies. Maintenance status is aging—last commit was 2025-09-20 but the package has not had a release since 2024-06-08, suggesting the project is stable but not actively developed. License in practice: MIT License (permissive) means you can use, modify, and distribute greenery freely in commercial and private projects with minimal restrictions, provided you include the license notice. Quickstart: pip install greenery from greenery import parse # Compute intersection of two regexes result = parse("abc...") & parse("...def") print(result) # "abcdef" Verify before relying: - Whether the package works with Python versions beyond 3.8, given the classifier lists only 3.8 and requires_python is unspecified. - Performance characteristics when working with complex or deeply nested regular expressions. ## Package facts - License: MIT License (permissive) - Python support: unspecified - Install friction: low - Maintenance: aging - Downloads: 250.5K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags regex intersection computation, regular expression manipulation, finite state machine regex, parse and combine regexes, regex set operations, pattern analysis tools, regex simplification, regex-algebra, formal-languages, finite-state-machines [View on SkillFed](https://skillfed.io/packages/greenery) · [View on PyPI](https://pypi.org/project/greenery/)