How do I write a regex without knowing regex?
Instead of reading regex docs and fighting with `\d+` and `[a-z]` by hand, paste examples of what you want to match and what you want to skip. The tool synthesizes 3-6 candidate regular expressions and shows which one fits best.
Left textarea: what should match (one example per line). Right textarea: what should NOT match. The algorithm: tokenize, align, generalize, verify. Output: a ready-to-use `/regex/flags` with a test panel for every example.
It tries the simplest patterns first (alternation `(opt1|opt2)`) then position-based matching, then structural patterns with quantifiers like `\d+`, `[a-z]+`. Shows every candidate, you pick or hand-tune.
How to use it
- In "Should match" paste 3-10 examples, one per line. More examples = better regex.
- In "Should NOT match" paste examples that must NOT match (e.g. malformed emails when targeting emails). Helps the tool reject patterns that are too broad.
- Tool generates several candidates automatically. Each shows: how many positives matched, how many negatives wrongly matched.
- Pick a candidate by clicking "Use this". A preview appears with per-example test results.
- Toggle "Manual edit" to tweak the chosen regex (e.g. add word boundaries `\b`, flags `(?i)`).
- Copy the final regex and paste into your code (JS, Python, Java, Go, PHP).
- If no candidate fits perfectly, add more examples (on either side). The algorithm learns from each new line.
When this is useful
Real situations where regex skills save you hours:
- Form validation: a "confirm email" field needs a regex. Generate one from 5 sample emails in 30 seconds.
- Log parsing: hunting for timestamp, IP, user-agent patterns in .log files. Feed 3-4 log lines, get a pattern.
- Cleaning CSV/Excel data: extracting phone numbers, ZIP codes, dates. Traditionally tedious, regex does it in one expression.
- Find & Replace in editors: VSCode, Sublime, IntelliJ all support regex search. One regex replaces 200 fragments at once.
- API validation: Express middleware, FastAPI Pydantic, NestJS pipes, all validate input via regex.
- Database migrations: `UPDATE table SET col = REGEXP_REPLACE(col, ...)` in Postgres, MySQL, Oracle.
- Web scraping: extracting URLs, emails, phone numbers from HTML (better tools exist for HTML parsing, but for simple cases regex is fine).
- Terminal search: `grep -E`, `ripgrep`, `ack` all use regex. Lightning-fast search across gigabytes of code.
- Input sanitization: check if a username only contains safe chars, if a tax ID has 10 digits, if an ISBN is valid format.
After generating a regex, test it interactively or convert to Python if you work in a different language.