exrex
Irregular methods for regular expressions
What it is and what it does
Exrex is a Python module and CLI tool that works backward from a regular expression to generate matching strings. Instead of testing whether a string matches a pattern, it produces strings that will match. It can enumerate all possible matches (useful for testing), pick random ones (useful for fuzzing), count how many exist, or simplify the pattern itself. The package uses generators to keep memory usage constant regardless of how many matches exist, making it practical for patterns with large or infinite match spaces.
The tool is pure Python with no external dependencies, making it trivial to install. It supports both programmatic use through functions like `getone()`, `generate()`, and `count()`, and direct command-line invocation with options to limit output, write to files, or run in random mode. Patterns with infinite repetition (like `[a-z]+`) are handled by capping the maximum length of those parts.
Use it for:
- Generate test data matching a regex pattern for unit tests or property-based testing frameworks
- Fuzz testing: produce random strings matching an input format to find edge cases in parsers or validators
- Verify regex correctness by examining all or a sample of strings the pattern actually matches
- Simplify complex regex patterns to equivalent but more readable forms for documentation or refactoring
- Count the number of possible matches for a pattern to understand its scope or validate assumptions
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Exrex generates all or random strings matching a given regular expression, counts matches, and simplifies regex patterns. It works as both a Python module and command-line tool with no external dependencies.
Yes, if you need to generate test data or validate regex patterns. The zero-dependency design and generator-based memory efficiency make it low-risk to add. However, the AGPLv3+ license requires careful review if you plan to distribute code that incorporates it; for internal testing or CLI use, this is less of a concern. No known vulnerabilities and active maintenance support the choice.
Install
exrex on PyPI
pip
pip install exrexuv
uv add exrexpoetry
poetry add exrexInstalling exrex
Before you install
Low friction: pure Python with no runtime dependencies, distributed as a wheel. Last commit 2026-02-24 with active maintenance status.
License in practice
Licensed under AGPLv3+. This is a copyleft license requiring derivative works and modifications to be released under the same terms; consider this carefully if you plan to distribute code that uses exrex.
Quickstart
pip install exrex
import exrex
# Generate a random matching string
print(exrex.getone('(ex)r\\1'))
# Generate all matching strings
print(list(exrex.generate('((hai){2}|world!)')))
# Count matching strings
print(exrex.count('[01]{0,9}'))
Infinite patterns (e.g., [a-z]+) are limited by exrex's maximum length setting; patterns with unbounded repetition will be truncated.
Verify before relying
- Whether the package handles all modern regex features (lookahead, lookbehind, named groups) or only a subset of the re module
- Performance characteristics on complex patterns with large match spaces
Package facts
| License | AGPLv3+ (agpl) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 639 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 518,516/month — #6,220 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: exrex-0.12.0-py3-none-any.whl
Keywords: regexp, generators, string, generation, regex, simplification
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
repathConverts Express-style path strings (like…
permissive · top 15,000 on PyPI
rstrGenerates random strings from custom alphabets,…
permissive · top 5,000 on PyPI
stringparserExtracts values from strings using…
permissive · top 15,000 on PyPI
greeneryParses and manipulates regular expressions by…
permissive · top 15,000 on PyPI
iregexp-checkValidates regular expressions against RFC 9485…
permissive · top 15,000 on PyPI
regexA drop-in replacement for Python's standard…
permissive · top 100 on PyPI
regressProvides Python bindings to the Rust regress…
permissive · top 5,000 on PyPI
rebulkReBulk provides a fluent API for building…
permissive · top 15,000 on PyPI
pytest-regexA pytest plugin that selects tests to run using…
permissive · top 15,000 on PyPI
argparse-extExtends Python's standard argparse module with…
copyleft · top 15,000 on PyPI