skillfed

greenery

Greenery allows manipulation of regular expressions

greenery v4.2.2 250.5K downloads/30d#8,627 on PyPI399
Permissive license MIT License AGING released

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 greenery

uv

uv add greenery

poetry

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 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

License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.8

Tags

regex intersection computationregular expression manipulationfinite state machine regexparse and combine regexesregex set operationspattern analysis toolsregex simplification
regex-algebraformal-languagesfinite-state-machines

More Text Processing packages