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.

You get: the regex in a code block, the breakdown table (Part, Meaning), a test table (String, Should match, Does match), a ready-to-run code snippet in my language, and a list of risks…

More like this

The prompt

regex-builder-with-match-and-no-match-test-cases.md
Act as a regular expression expert. I need a regex that does this: {describe what to match}

First ask me which language or tool will run it (for example JavaScript, Python, PCRE or grep) and for a few real example strings, if I have not given them.

Rules:
1. Write the simplest regex that works. Prefer readability over cleverness.
2. Explain it piece by piece in a table.
3. Test it against at least 6 strings that should match and 6 that should not, including tricky near-misses.
4. Warn about catastrophic backtracking, Unicode issues, or differences between regex flavours.
5. If the job is better done without regex, such as parsing HTML, JSON or email addresses fully, say so and suggest the alternative.

Output format: the regex in a code block, the breakdown table (Part, Meaning), a test table (String, Should match, Does match), a ready-to-run code snippet in my language, and a list of risks and assumptions.

Tips and common edits

Use when you need a pattern for validation, search or log parsing. Works in ChatGPT, Claude or GitHub Copilot chat; always run the test snippet before shipping.

Questions about this prompt

More in Coding

Regex with Match and Non-Match Test Strings

Writes a regex for your pattern, explains each part and provides 8 strings that should match and 8 that should not.

Edge-Case Test Suite for One Function in Your Existing Test Framework

Writes tests for a single function that cover normal inputs, boundaries, bad input and error paths, in the test framework your project already uses.

Plain-English Question to a Correct SQL Query for Your Schema

Writes a SQL query from a plain-English question using your real table definitions, explains each part, checks it for common mistakes and suggests indexes if it will be slow.

Characterization Tests Before a Refactor

Writes tests that lock in a module's current behavior, including edge cases and quirks, so you can refactor safely.

Codebase Tour for a Specific Task

Explores a repo through the lens of your task and explains the architecture, key files and data flow, then says where to start.

Debug an Error From the Message and the Code Around It

Finds the most likely cause of an error from the message and the relevant code, ranks other possible causes, and gives the smallest fix plus a way to prove it worked.

Explain a Codebase Folder to a New Developer on Their First Day

Produces an onboarding guide for one folder of a codebase: what it does, how data moves through it, the files to read first and the traps a new developer should avoid.

Failing Test First Bug Fix

Reproduces a bug with a failing test, finds the root cause, applies the smallest fix and shows the test passing.

Pull Request Review with Merge Recommendation

Reviews a diff against your standards and returns a merge, merge-with-changes, or do-not-merge recommendation. Findings are ranked by severity, with evidence, suggested fixes, and open questions.

Root Cause Analysis from Stack Trace and Logs

Turns an error report, stack trace, and logs into ranked root-cause hypotheses. Includes the cheapest checks to confirm each one, a fix proposal, and a regression test plan.

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.

Architecture Decision Record for a Technology Choice

Compares realistic options against your constraints and produces a decision record. The record has a weighted comparison, risks, a reversal plan, and a recommendation the team can approve or challenge.