Regex pattern from examples you provide

Get a regular expression that matches your examples and rejects your counter-examples, with an explanation and test cases for your language.

Published
Works with
ChatGPT, Claude and Gemini
Level
Intermediate
By
GoodAIPromt editorial team

Regular expressions are powerful and hard to read, and a pattern that looks right often matches things it shouldn't. Giving clear examples of what should and shouldn't match is the best way to get a correct one. This prompt builds the pattern from those examples and tests it.

The prompt

You are a regex expert. Write a regular expression for me.

Language or tool where it will run: 
What I want to match or extract, in plain words: 
Strings that SHOULD match (and what to capture): 
Strings that should NOT match: 

Give me:
1. The regex, with the flags needed.
2. A part-by-part explanation.
3. A table testing it against every example I gave: string, expected, actual result, captured groups.
4. 5 edge cases I didn't think of and how the pattern handles them.
5. A code snippet in my language that uses it.
6. Warnings about performance (e.g. catastrophic backtracking) or cases where a parser would be better than regex.

Use syntax supported by my language only.

0 of 4 blanks filled

How to use it

  1. Give at least 5 matching and 5 non-matching examples.
  2. Test the pattern in your code or on a regex testing site.
  3. Add the test cases to your unit tests.

Tips

  • Ask for a version with named groups for readability.
  • Don't use regex to parse HTML or nested structures.

Frequently asked questions

What does this prompt do?

Get a regular expression that matches your examples and rejects your counter-examples, with an explanation and test cases for your language.

Which AI tools does it work with?

It is written for ChatGPT, Claude and Gemini. It also works in other AI tools that accept text prompts, with small changes.

What do I need to fill in?

4 blanks: e.g. javascript, python, postgresql, vs code search; goal; match examples; non-match examples. Click each blue blank on the page, type your details and press Copy prompt.

Is this prompt free to use?

Yes. You can copy and use it for personal and commercial work.

regexregular expressionstext parsing

More prompts for ChatGPT, Claude, Gemini.