greenery
Greenery allows manipulation of regular expressions
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 on this page — 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
greenery on PyPI
pip
pip install greeneryuv
uv add greenerypoetry
poetry add greeneryInstalling 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 | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | aging — 797 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 250,525/month — #8,627 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: greenery-4.2.2-py3-none-any.whl
Keywords: re, regex, regexp, regular, expression, deterministic, finite, state, machine, automaton, fsm, dfsm, fsa, dfsa, greenery
Tags
More Text Processing packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyparsingpyparsing provides a library for building text…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
RapidFuzzRapidFuzz provides fast fuzzy string matching…
permissive · top 1,000 on PyPI
tinycss2tinycss2 parses CSS strings into token and…
permissive · top 1,000 on PyPI
llama-parseLlamaParse parses complex documents (PDFs,…
permissive · top 1,000 on PyPI
interegularInteregular checks whether pairs of Python…
permissive · top 5,000 on PyPI
regexploitRegexploit analyzes regular expressions to…
permissive · top 15,000 on PyPI
repathConverts Express-style path strings (like…
permissive · top 15,000 on PyPI
exrexExrex generates all or random strings matching…
agpl · top 15,000 on PyPI
iregexp-checkValidates regular expressions against RFC 9485…
permissive · top 15,000 on PyPI
retrieBuilds efficient Trie-based regex patterns for…
permissive · top 15,000 on PyPI
suffix-treesImplements suffix trees and generalized suffix…
permissive · top 15,000 on PyPI
flpcflpc wraps the Rust regex crate to provide…
permissive · top 5,000 on PyPI
tag-expressionsParses and evaluates logical tag expressions…
copyleft · top 15,000 on PyPI