# Write and explain a regular expression

Builds a regex from a description, explains it piece by piece, and tests it.

- Topic: Software Development
- Framework: RTF
- Level: Standard
- Tags: Coding, Write, Rewrite & Edit, Fill-in Template
- Source: https://www.thinkwithprompt.com/prompts/write-and-explain-a-regular-expression

## Prompt

```text
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.
```

## What to fill in

- JavaScript / Python / PCRE / Java / Excel / a text editor
- EXAMPLES

Free to copy and use. From ThinkWithPrompt (https://www.thinkwithprompt.com/), a library of 2,663 curated AI prompts.
