Write and explain a regular expression
Builds a regex from a description, explains it piece by piece, and tests it.
The prompt
Write a regular expression for me.
What it should match: [DESCRIPTION — e.g. "UK postcodes", "dates like 2026-03-14", "emails but not ones ending in .test"]
Where I'll use it: [JavaScript / Python / PCRE / Java / Excel / a text editor]
Should match: [EXAMPLES]
Should NOT match: [EXAMPLES]
Return:
1. The regex in a code block.
2. A piece-by-piece explanation.
3. A test table showing each of my examples and whether it matches.
4. Edge cases it doesn't handle, and a stricter or looser variant if useful.
Prefer readable patterns over clever ones; note any flavor-specific syntax.
Highlighted [brackets] are blanks to replace with your own details.
Fill in the blanks and use this promptMore Software Development prompts
What to fill in
- JavaScript / Python / PCRE / Java / Excel / a text editor
- EXAMPLES
How this prompt is built
This prompt follows the RTF structure (Role, Task, Format). RTF tells the model who to be, what to do and what shape the answer should take. It is the quickest structure that still gives noticeably better results than a bare request.
Related prompts
- Diagnose and improve my mobile app's performanceA performance review of an iOS or Android app covering startup time, jank, memory, battery, network, and crashes, with tools and a fix plan.
- Refactor code to be cleaner and easier to maintainImproves structure, naming, and design without changing behavior.
- Convert code to another language or frameworkIdiomatic translation of code between languages or frameworks, with notes on differences.
- Write unit tests for my codeComprehensive unit tests covering happy paths, edge cases, and failures.