Debug Regex and Parsers with GitHub Copilot
Generate an automated audit of regular expressions or parser snippets that flags catastrophic backtracking, isolates edge cases, and produces unit test fixtures.
Agent prompt for ChatGPT and Claude
You get: Vulnerability and Performance Analysis, failure Root Cause and optimized Implementation
Prompt
mkdir -p .agents/skills/debug-regex-and-parsers-with-github-copilot && curl -sL "https://prompts-gpt.com/prompts/debug-regex-and-parsers-with-github-copilot/raw" -o .agents/skills/debug-regex-and-parsers-with-github-copilot/SKILL.mdAct as a compiler engineer and regex security specialist. I will paste a regular expression or token parser snippet below along with sample inputs that fail or run slowly.
Analyze the code using these rules:
1. Break down the pattern into logical match groups and identify catastrophic backtracking risks (nested quantifiers or overlapping alternatives).
2. Explain why the provided sample inputs cause failures, timeouts, or unexpected captures.
3. Provide a corrected, safer pattern or equivalent sequential parser code with zero exponential complexity risk.
4. Write a compact test fixture table listing at least three valid strings, three invalid strings, and two adversarial edge cases.
Output format:
- Vulnerability and Performance Analysis (state time complexity in big-O notation)
- Failure Root Cause (bulleted breakdown of the pasted samples)
- Optimized Implementation (the clean regex or code snippet)
- Test Fixtures (Markdown table with columns: Input String, Expected Match, Purpose)
End with one short line identifying any parser engine limitations (such as ECMAScript vs PCRE2 features).Example output
Tips and common edits
Why this works
- Forces an explicit Big-O complexity check to stop catastrophic backtracking and ReDoS vulnerabilities before deployment.
- Requires an exact tabular test fixture with adversarial inputs to catch boundary regressions instantly.
- Bans nested greedy loops by mandating safe, linear patterns or explicit sequential parser alternatives.
Paste this directly into GitHub Copilot Chat, Claude, or ChatGPT along with your problematic regex string or token parsing logic and sample failed inputs.
Common edits
- Specify your language runtime (e.g. Node.js V8 or Go regexp) to swap standard regex for native non-backtracking engines.
- Request the corrected parser as an iterative finite-state machine instead of a regular expression.
Reuse it: Use in a workflowAdapt in the builder
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
More like this
Turn Sentry Errors into Reproducible Codex Test Cases
Transforms a production Sentry stack trace and context payload into a self-contained failing unit test designed for Codex repo tasks.
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.
Generate Boundary Condition Unit Tests for GitHub Copilot
Get a comprehensive unit test suite focusing on edge cases, null pointers, and arithmetic overflows for any function you paste.
Evaluate Coding Agent Test Suites for False Positive Traps
Audits agent-generated unit tests to catch tautological assertions, over-mocking, and tests that still pass when core business logic is disabled.
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.
Unit Test Plan and Test Code for an Existing Function
Builds a behavior-based test matrix for a function or module and then generates test code in your framework. Covers edge cases, failures, and mocking boundaries, with coverage gaps stated honestly.
- Document module behavior from its test suite
- Generate Reproducible Bug Fix Specs for Coding Agents
- Debug Broken Spreadsheet Formulas and Lookup Errors in Canvas
- Scope a JavaScript to Strict TypeScript Codex Task
- Refactor Pasted Code for Readability Without Changing Its Behavior
- Debug an Error From the Message and the Code Around It