exrex
Generate strings matching a regular expression
TLDR
Generate all possible strings that match a regex
Generate a random string that matches a regex
Generate at most 100 strings that match a regex
Generate all possible strings that match a regex, joined by a custom delimiter string
Print count of all possible strings that match a regex
Simplify a regex
Print eyes
Print a boat
SYNOPSIS
exrex [OPTIONS] [REGEX [COUNT]]
PARAMETERS
-h, --help
Show help message and exit
-v, --version
Show version and exit
-l LIMIT, --limit LIMIT
Limit total generated strings (prevents infinite output)
-o FILE, --output FILE
Write output to FILE instead of stdout
-g, --generate
Generate all matches (up to limit); overrides COUNT
-1, --one
Generate exactly one matching string
DESCRIPTION
Exrex is a command-line tool for generating all possible strings matching a given regular expression using a backtracking algorithm. It systematically explores the regex structure to produce matches in deterministic order, ideal for testing parsers, fuzzing inputs, creating test data, or enumerating regex possibilities.
By default, exrex REGEX COUNT generates COUNT matching strings (default 1). Use -g to generate all matches up to a limit, preventing hangs on unbounded patterns like a*. Supports Python re syntax: alternations, quantifiers, groups, lookarounds (with caveats for complexity).
Example: exrex '[a-z]{2}' outputs all 676 two-letter lowercase combinations. Limit output with -l 10 or redirect via -o file.txt. Exponential growth in nested quantifiers can lead to high CPU/memory use; always test small patterns first.
Perfect for security testing, input validation verification, or educational regex demos.
CAVEATS
Unbounded regex (e.g., a*, (ab)?) may loop infinitely without -l. Nested quantifiers cause exponential time/space. Lookaheads/backrefs increase complexity. Not for production on huge finite sets (e.g., [a-z]{10} = 1.4e14 strings). Test with small limits.
EXAMPLES
exrex 'ab|c'
ab
c
exrex '[0-9]{3}' -l 5
000
001
002
003
004
exrex '(a|b){1,2}' -g
Generates: a, b, aa, ab, ba, bb
INSTALLATION
pip install exrex or apt install exrex (some distros); source from GitHub.com/asciimoo/exrex
HISTORY
Developed by Laszlo Boszormenyi (asciimoo) in Python; first GitHub release ~2015. Evolved for better backtracking efficiency. Installed via pip install exrex or distro packages (e.g., AUR). Actively maintained for regex testing needs.


