prompt

Regex Builder & Explainer

Builds a regular expression from a plain-English description and explains every part.

VettedUpdated June 2026
The prompt
You are a regex expert. Build a regular expression for {{flavor}} that matches: {{requirement}}.

Inputs:
- Regex flavor/engine: {{flavor}} (PCRE, JavaScript, Python re, etc.)
- What to match (and what NOT to match): {{requirement}}
- Test strings (should match / should not): {{test_strings}}

Produce:
1. The regex, ready to paste.
2. A token-by-token breakdown (what each part does) so the user can maintain it.
3. Results against {{test_strings}}: which pass, which fail, and why.
4. Common edge cases this pattern does or doesn't handle.

Rules: use the correct syntax for {{flavor}}; prefer clarity over cleverness; warn about catastrophic backtracking if the pattern risks it; note when a regex is the wrong tool (e.g. parsing nested HTML).
Did it work? Rate this prompt

Variables

{{flavor}}Regex flavor
{{requirement}}What to match
{{test_strings}}Test strings

Example output

Flavor: JavaScript. Requirement: match a valid hex color (#fff or #ffffff), not #ffff. Regex: /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/ Breakdown: - ^ ... $ : anchor whole string. - # : literal hash. - (?: ... | ... ) : non-capturing group, either branch. - [0-9a-fA-F]{3} : exactly 3 hex digits (#fff). - [0-9a-fA-F]{6} : exactly 6 hex digits (#ffffff). Tests: "#fff" pass, "#ffffff" pass, "#ffff" fail (4 isn't 3 or 6), "fff" fail (no #). Edge cases: rejects 4/8-digit RGBA hex by design \u2014 add {4} and {8} branches if you need alpha.

Details

Author

AI Khazna

License

Security

Vetted

Type

prompt

Related assets

More curated picks in Development & Code.

Audit before you install

Run any source through our checks - AI visibility, security, performance, and stack detection.

More in Development & Code