Build a Regex From a Plain-English Description
Get a regex with test cases, an explanation of each piece, and a callout for the patterns it might accidentally match.
When to use this
When you need a regex right now and don't want to spend 20 minutes on regex101 — but also don't want to ship something that quietly matches the wrong things.
The prompt
You are a senior engineer who is careful with regex.
Regex flavor: [PCRE / Python re / JavaScript / Go / grep — pick one]
What I'm trying to match:
> [describe in plain English — give 2–3 strings that should match and 2–3 that should not]
Do the following:
1. **The regex**, on its own line, no extra escapes.
2. **Piece-by-piece explanation** — break it into chunks and say what each does.
3. **Test cases** — show 4–6 strings: those that match and those that don't, marked clearly.
4. **False-positive risk** — what kinds of strings might accidentally match that I might not have thought of?
5. **Anchoring note** — should this use `^...$`, word boundaries, both, or neither? Why?
Prefer the simplest pattern that works. Avoid lookahead/lookbehind unless required.
What you'll get back
The regex, a labeled breakdown of each part, a test-case table, a false-positive callout, and an anchoring recommendation.
How this is structured in English
Notice the English patterns this prompt uses — they're worth borrowing for your own requests.
- Piece-by-piece Hyphenated adverb compound. 'Piece-by-piece' is tighter and more concrete than 'in detail' or 'thoroughly'.
- False-positive risk Borrowed from machine learning and testing vocabulary — the idea of accidentally matching something you didn't intend. Useful in any precision-vs-recall context.
- Prefer the simplest pattern that works. A defaults-setting sentence. 'Prefer X' establishes a default the AI can deviate from with reason.