wowprompt

Regex pattern builder with test cases and explanation

Builds a regular expression for a described pattern, explains each part and proves it against strings that should and should not match. Use it for validation, search and replace, or extracting values from text and logs.

A regex pattern, a token-by-token explanation table and a test table of matching and non-matching strings with results
The output this prompt produced, unedited.

The prompt

Goal

Write a regular expression that matches exactly what is described and nothing more, then prove it with tests.

Inputs

  • What to match: [e.g. Indian mobile numbers with optional +91, or order IDs like ORD-2026-00451]
  • Purpose: [validate a full field, find inside text, extract a group, search and replace]
  • Regex flavour: [JavaScript, Python, PCRE, Java, .NET, Google Sheets RE2]
  • Examples that should match: [paste examples]
  • Examples that should not match: [paste examples, or leave blank]

Output format

  1. The pattern on its own line, with any flags named separately.
  2. Explanation table:

| Part | Meaning |

  1. Test table with at least eight should-match and eight should-not-match strings:

| String | Should match | Does match | Captured group, if any |

  1. Usage line: one line showing how to apply the pattern in the stated language.
  2. Limits: cases the pattern deliberately does not handle.

Check before answering

  • Anchors are used for full-field validation and omitted for search inside text.
  • The pattern uses only features supported by the stated flavour; for example, no lookbehind where it is unsupported.
  • No nested quantifiers that could cause catastrophic backtracking.
  • Special characters are escaped correctly.
  • Every row in the test table is evaluated correctly against the final pattern.
  • Groups are non-capturing unless the value needs extracting.
  • The pattern is as simple as the requirement allows.
regex generatorregular expression builderregex examplesregex for validationregex tester

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity