In the pack: ChatGPT, Claude & Gemini Prompts for Coding and Developers
Write and Test a Regular Expression
Prompt
Regex flavor or language (Python re, JavaScript, PCRE, Go RE2, POSIX grep): {{REGEX_FLAVOR}}
What to match or extract: {{MATCH_GOAL}}
Examples that must match: {{SHOULD_MATCH}}
Examples that must not match: {{SHOULD_NOT_MATCH}}
Do this:
1. Ask yourself whether a regex is the right tool; if a parser or standard library function is safer (for URLs, email, HTML, JSON, dates), say so first.
2. Write the regex, then a verbose or commented version that explains each part.
3. Explain the anchoring, greediness and flags used, and how it handles Unicode and line breaks in my flavor.
4. Check for catastrophic backtracking (nested quantifiers such as (a+)+) and say whether this pattern is at risk on long input.
5. Write a runnable test in my language that asserts every "should match" and "should not match" example, plus five edge cases you add.
6. List inputs it will still get wrong, honestly.
Use only features my flavor supports. Go's RE2, for example, has no lookbehind.
Customize this prompt
Fill in the variables below to personalize this prompt:
Model Settings
Recommended Models
Temperature
Max Tokens
Additional Notes
About this prompt
“Write and Test a Regular Expression” is a free prompt for ChatGPT in the Coding & Software category, 183 words long, added to The Prompt Index on October 28, 2026 by The Prompt Index. Copy it with the button above, paste it into ChatGPT or any other AI chat assistant, and send it.
It has 4 placeholders to fill in first:
{{REGEX_FLAVOR}}, {{MATCH_GOAL}}, {{SHOULD_MATCH}}, {{SHOULD_NOT_MATCH}}.
Use the “Customize this prompt” fields to personalise it before you copy.
Recommended models: ChatGPT, Claude, Gemini.
0 upvotes, sent to an AI tool 0 times, viewed 3 times.
Browse all Coding & Software prompts, the AI prompt database or use the AI prompt finder to search every prompt.