Build and explain a regular expression

Writes a regex from plain-English rules plus examples that should and should not match, then explains each part.

Prompt, 4 blanks to fill
Write a {{FLAVOUR}} regular expression.

Goal: {{GOAL}}

Should match:
{{MATCH_EXAMPLES}}

Should NOT match:
{{NO_MATCH_EXAMPLES}}

Return:
1. The pattern on its own line.
2. A breakdown of each part in plain English.
3. A table showing each example and whether the pattern matches it. Check carefully, one by one.
4. Any edge cases my examples do not cover that I should decide on.

Prefer a readable pattern over a clever one.

Example output

Pattern: ^[A-Z]{2}\d{2} ?\d{4}$ Breakdown: two capital letters, two digits, optional space, four digits. Checked: 4 of 4 should-match pass, 3 of 3 should-not-match fail.

How to use

Give at least 3 examples in each list, including tricky near-misses. FLAVOUR is the engine, such as "JavaScript", "Python re" or "PCRE". Test the pattern in your own code or a regex tester before using it.

Why it works

Examples on both sides pin down exactly what you mean, which plain descriptions rarely do. The match table forces the model to check its own work, though you should still verify it because models do make regex mistakes.

Find a prompt for the task in front of you.

96 prompts in 8 categories. Copy one, fill in the blanks, paste it into any model.

Browse prompts

Promptlexity is a free library of 96 AI prompts and 8 downloadable AI skills across 8 categories, plus a glossary of 64 AI and prompting terms. Each prompt shows the exact text to paste, the variables to fill in, an example of what comes back, and why it works. Each glossary term has a plain-English definition, an example and a common mistake. 6 step-by-step guides cover the basics. No signup, works with ChatGPT, Claude, Gemini and other models.

Press Esc to close