b536daa983c0abffc42af90d03589bea65c222e2
- Add tests directory with comprehensive test suite - Add development configuration files (requirements-dev.txt, setup.cfg) - Add pre-commit hooks and gitignore for project hygiene - Ensure CI workflow has all necessary files to run 121 tests
Regex Humanizer CLI
A CLI tool that converts complex regex patterns to human-readable English descriptions and generates comprehensive test cases.
Features
- Regex to English Translation: Convert any regex pattern to plain English
- Test Case Generation: Auto-generate matching and non-matching test inputs
- Multi-Flavor Support: Supports PCRE, JavaScript, and Python regex flavors
- Interactive Mode: REPL-style interface for exploring regex patterns
- Pattern Validation: Validate regex patterns for different flavors
- Flavor Conversion: Convert patterns between different regex flavors
Installation
pip install regex-humanizer-cli
Or from source:
pip install -e .
Quick Start
Explain a regex pattern
regex-humanizer explain "^\d{3}-\d{4}$"
Output:
Pattern: ^\d{3}-\d{4}$
Flavor: pcre
English Explanation:
--------------------------------------------------
at the start of line or stringany digit (0-9)any digit (0-9)any digit (0-9)hyphenany digit (0-9)any digit (0-9)any digit (0-9)any digit (0-9)at the end of line or string
Generate test cases
regex-humanizer test "^[a-z]+$"
Output:
Pattern: ^[a-z]+$
Flavor: pcre
Matching strings (should match the pattern):
--------------------------------------------------
1. abc
2. hello
3. world
Non-matching strings (should NOT match the pattern):
--------------------------------------------------
1. 123
2. Hello
3. test123
Interactive mode
regex-humanizer interactive
Commands
explain
Explain a regex pattern in human-readable English:
regex-humanizer explain "PATTERN" [OPTIONS]
Options:
--output, -o: Output format (text/json, default: text)--verbose, -v: Show detailed breakdown--flavor, -f: Regex flavor (pcre/javascript/python)
test
Generate test cases for a regex pattern:
regex-humanizer test "PATTERN" [OPTIONS]
Options:
--output, -o: Output format (text/json, default: text)--count, -n: Number of test cases (default: 5)
interactive
Start an interactive REPL for exploring regex patterns:
regex-humanizer interactive [OPTIONS]
Options:
--flavor, -f: Default regex flavor
flavors
List available regex flavors:
regex-humanizer flavors
validate
Validate a regex pattern:
regex-humanizer validate "PATTERN" [OPTIONS]
Options:
--flavor, -f: Specific flavor to validate against
convert
Convert a regex pattern between flavors:
regex-humanizer convert "PATTERN" --from-flavor pcre --to-flavor javascript
Flavor Support
| Feature | PCRE | JavaScript | Python |
|---|---|---|---|
| Lookahead | ✅ | ✅ | ✅ |
| Lookbehind | ✅ | ⚠️ Limited | ✅ |
| Named Groups | ✅ | ✅ | ✅ |
| Possessive Quantifiers | ✅ | ❌ | ❌ |
| Atomic Groups | ✅ | ❌ | ❌ |
Configuration
No configuration file required. All options can be passed via command line.
Development
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
# Run linting
ruff check regex_humanizer/
# Run type checking
mypy regex_humanizer/ --ignore-missing-imports
License
MIT License