Regex Wizard
Generate, test, and explain regular expressions from plain English.
Requirements
python3,grep -P, ornodefor testing regex (at least one)- No API keys needed
Instructions
Generate regex from description
- Clarify ambiguous requirements (multiline? global? case-insensitive?)
- Produce the pattern with flavor noted (Python, JS, PCRE, Go)
- Explain each component in plain English
- Show 3+ example matches and 2+ non-matches
Explain existing regex
- Break into tokens/groups with inline annotations
- Explain in simple language (avoid jargon)
- Show example strings that match and don't match
- Note the assumed flavor and any flavor-specific features used
Test regex against strings
Run the pattern against provided test strings:
# Python (most portable)
python3 -c "
import re
pattern = r'YOUR_PATTERN'
tests = ['test1', 'test2', 'test3']
for t in tests:
m = re.search(pattern, t)
print(f'{t!r}: {\"✅ Match\" if m else \"❌ No match\"}' + (f' → groups: {m.groups()}' if m else ''))
"
# Grep (quick check)
echo "test string" | grep -P 'pattern'
Output format
**Pattern**: `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
**Flavor**: Python/PCRE
**Flags**: None
| Component | Meaning |
|-----------|---------|
| `^` | Start of string |
| `[a-zA-Z0-9._%+-]+` | One or more valid email chars |
| `@` | Literal @ |
| `[a-zA-Z0-9.-]+` | Domain name |
| `\.[a-zA-Z]{2,}$` | TLD (2+ letters) at end |
**Matches**: `user@example.com`, `a.b+c@test.co.uk`
**Non-matches**: `@example.com`, `user@`, `user@.com`
Common Pitfalls to Warn About
- Greedy vs lazy:
.*vs.*?— explain when it matters - Catastrophic backtracking: Nested quantifiers like
(a+)+— always flag these - Unescaped dots:
.matches any char, not just literal dots - Anchors: Missing
^/$can cause partial matches - Unicode:
\wbehavior differs across flavors (Python 3 includes Unicode by default)
Edge Cases
- Email/URL validation: Warn that perfect regex for these is extremely complex. Suggest using libraries instead for production.
- Multi-line input: Remind about
re.DOTALL/re.MULTILINEflags. - Empty string matching: Patterns like
.*match empty strings — clarify if that's intended.
Security
- Never use user-supplied regex directly in production without timeout/limits (ReDoS risk).
- When testing regex against user data, sanitize the test strings in output.