Explain Any Regex Token by Token with Matching and Failing Examples
Get a token-by-token table explaining your regex, plus strings that match, nearly match and fail, and a clear catastrophic backtracking risk check with a safer rewrite.
You getPurpose, token table with columns and matches
Prompt
You are a senior developer who reviews regular expressions in code reviews and explains them to teammates.
I will paste a regex right after this message. If I don't say which regex flavor it is (JavaScript, Python, PCRE, Java, .NET, Go) or what it is meant to match, ask me those 2 questions in one numbered message and wait for my answers.
Then explain the pattern. Rules:
1. Split it into the smallest meaningful tokens, in order. Groups get one row for the whole group, then a row for each token inside it.
2. Describe each token in plain English, with no regex jargon left unexplained.
3. Give 3 strings that match, 3 that nearly match but fail, and 3 that clearly fail. For every near miss, name the exact token that rejects it.
4. Check for catastrophic backtracking: nested quantifiers, overlapping alternatives, or optional separators inside repeated groups. Rate the risk Low, Medium or High and show a short input that triggers it.
5. If the risk is Medium or High, or the pattern has a bug, give a corrected version and say what changed.
Output format:
- Purpose (one sentence)
- Token table with columns: Token, Meaning, Example it matches
- Matches, Near misses (with rejecting token), Fails
- Backtracking risk (rating, trigger input, reason)
- Suggested rewrite (if needed)
End with one line on any flavor-specific behavior or assumptions you made.Example output
Tips and common edits
Why this works
- Naming the exact token that rejects each near miss shows how the pattern behaves at its edges, not just on the happy path.
- Asking for a concrete trigger input makes the backtracking warning testable instead of a vague caution.
- Requiring the regex flavor up front avoids wrong answers about lookbehinds, flags and escapes that differ between engines.
Use this in ChatGPT, Claude or Gemini when you inherit a regex you don't understand or before shipping one to production. Have the pattern, its flavor, and what it should match ready.
Common edits
- Ask for unit tests in your language (Jest, pytest) built from the match and fail lists.
- Drop the backtracking section for simple patterns and ask for a one-paragraph summary instead.
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
Keep exploring
More like this
Resolve a Git Merge Conflict and Keep What Both Branches Intended
Paste your conflict markers and get a plain explanation of each side's change, a merged version that keeps both intents, and a test checklist.
Review a Beginner's Code with Kind, Prioritized Feedback on the Top 3 Fixes
Paste your code and get a mentor-style review with one specific compliment, the three highest-impact fixes ranked with corrected snippets, and one next step.
Refactor Pasted Code for Readability Without Changing Its Behavior
Returns a cleaner version of your code plus a change log that explains each edit, why behavior is preserved, and which edge cases you should test.
Regex Builder With Match and No-Match Test Cases
Builds a regular expression from a plain-English description and example strings, explains each part, and proves it against strings that should and should not match.
Explain a Complex SQL Query in Plain English, Step by Step
Get a plain-English walkthrough of any SQL query in execution order, with tiny sample tables, row counts after each clause, and the hidden gotchas.
Optimize a Slow SQL Query Using Its EXPLAIN Plan Step by Step
Paste a slow query and its EXPLAIN output to get the costliest plan node named, exact CREATE INDEX or rewrite fixes, and a clear way to verify the speedup.