Regex generator: a regular expression with tests that prove it works
Regular expressions are short, powerful and easy to get subtly wrong. Describe what should match and what shouldn't, and your todo.is agent writes the regex for your language or tool, explains every token, and runs it against your examples so you can see each match and miss before you ship it.
The prompt
- Write a regular expression that matches [WHAT SHOULD MATCH] and does not match [WHAT SHOULD NOT MATCH]. I'll use it in [LANGUAGE OR TOOL] to [WHAT YOU WILL DO WITH IT]. Explain each part of the pattern in plain words. Test it in your workspace against my examples here: [EXAMPLES] and add 10 tricky cases of your own, then show me a table of input, expected and actual result. Keep it readable rather than clever.
What to change
- [WHAT SHOULD MATCH]: E.g. "UK postcodes like SW1A 1AA and M1 1AE" or "order numbers like ORD-2026-00123".
- [WHAT SHOULD NOT MATCH]: E.g. "postcodes inside longer words" or "order numbers with fewer than 5 digits".
- [LANGUAGE OR TOOL]: E.g. "JavaScript", "Python re", "Google Sheets REGEXMATCH", "VS Code search", "grep -E", "PostgreSQL".
- [WHAT YOU WILL DO WITH IT]: E.g. "validate a form field", "extract all matches from log text", "find and replace".
- [EXAMPLES]: Paste 5-20 real lines, good and bad. Remove personal data first.
Example result
- Regex for order numbers (JavaScript)
- Matches ORD-2026-00123 style IDs inside text: "ORD", a 4-digit year, then 5 or 6 digits.
- Pattern:
- /\bORD-(20\d{2})-(\d{5,6})\b/g
- What each part means
- • \b a word boundary, so "XORD-2026-00123" won't match
- • ORD- the literal prefix (case-sensitive; add the i flag to allow "ord-")
- • (20\d{2}) group 1: a year from 2000 to 2099
- • - a literal hyphen
- • (\d{5,6}) group 2: the order number, 5 or 6 digits
- • \b another boundary, so "ORD-2026-0012345" (7 digits) won't match
- • g find every match in the text, not just the first
- Test table
- • ORD-2026-00123 → match (expected match)
- • Ref: ORD-2025-104233, thanks → match "ORD-2025-104233"
- • ORD-2026-0012 → no match (only 4 digits)
- • ORD-2026-0012345 → no match (7 digits)
- • ORD-1999-00123 → no match (year before 2000)
- • XORD-2026-00123 → no match (letter before the prefix)
- • ord-2026-00123 → no match (lowercase; use /i if it should match)
- All 25 inputs, yours plus 10 edge cases, gave the expected result.
- Using it
- • Extract all IDs: text.match(/\bORD-(20\d{2})-(\d{5,6})\b/g)
- • Python: re.findall(r"\bORD-(20\d{2})-(\d{5,6})\b", text) returns (year, number) pairs
- • Validate a whole field: use ^ and $ instead of \b: /^ORD-(20\d{2})-(\d{5,6})$/
How to do it with todo.is
- Copy the prompt and describe what should and shouldn't match.
- Paste real examples, both good and bad, into the brackets.
- Send it from the Today screen in todo.is or on WhatsApp or Telegram.
- Your agent returns the pattern, the explanation and a test table showing every result.
- Paste a line that fails in real life and ask it to update the pattern and rerun the tests.
Tips for a better result
- Name the regex flavour. JavaScript, Python, PCRE, Google Sheets (RE2) and grep differ: RE2 has no lookbehind, and grep needs -E or -P.
- Give counter-examples. What must NOT match shapes the pattern as much as what should.
- For validation use ^ and $ anchors; for finding inside text use \b word boundaries.
- Don't use regex to parse HTML, email addresses to the letter of the standard, or nested structures. Ask your agent for a parser instead.
- Keep the test table. When the rules change, send it back with the new cases.
regex generator: FAQ
- What is a regex generator? It turns a plain-language description and examples into a regular expression. Here your agent also tests the pattern and explains it, so you aren't pasting something you can't read.
- Why does my regex work in one language but not another? Regex engines differ. Lookbehind, named groups, \d with Unicode digits and flags behave differently across JavaScript, Python, Java, PCRE and RE2, so say where you'll use it.
- How do I match a whole line instead of part of it? Wrap the pattern with ^ at the start and $ at the end. In multi-line text add the m flag so they apply to each line.
- Can a regex be slow? Yes. Nested quantifiers like (a+)+ can cause catastrophic backtracking on long input. Ask your agent to check the pattern for this if it runs on user input.
JavaScript is required to use the todo.is app.