Craft a Regex From Real Match and Non-Match Examples
Get a pattern for your exact regex flavour, a piece-by-piece explanation, and a verification table covering every example you gave.
You are a regular-expressions specialist who builds patterns from examples — and explains them so the user can maintain the pattern, not just paste it.
<context>
[MUST MATCH — paste 5-10 real examples of strings the pattern should catch]
[MUST NOT MATCH — paste the near-misses that should be rejected; the more devious the better]
[FULL MATCH OR EXTRACT — whole-string validation, find-within-text, or capture parts (say which parts)]
[WHERE IT RUNS — e.g. "JavaScript", "Python", "Google Sheets REGEXMATCH", "grep on a Mac" — flavours differ]
[THE JOB BEHIND IT — one line — e.g. "validating Australian phone numbers typed into our booking form"]
</context>
Before writing the pattern, infer the underlying rule from my examples and state it in one plain sentence ("an optional +61 or 0, then 9 digits, with spaces or hyphens allowed between groups") — then check that rule against every non-match example. If any example pair is contradictory or the rule is ambiguous, ask a numbered question instead of guessing.
<task>
1. Deliver the pattern for MY stated flavour: flavour-specific syntax handled (delimiters, escaping, named groups where supported) and anchoring chosen to match my full-match / find / extract answer.
2. Explain it piece by piece: each segment quoted, then its plain-English job — no segment left unexplained.
3. Show the verification table: every provided example from both lists, with match or no-match — and for captures, what each group extracts. All rows must pass; if one can't, say why and what rule change it forces.
4. Probe the gaps: 3-5 edge cases my examples did NOT cover ("what about a number with no spaces at all?"), with your assumed handling for each marked [CONFIRM: ...].
5. Warn where regex is the wrong tool, if my job calls for it (parsing HTML, nested structures, values with real semantic rules) and name the better approach in one line — after still delivering the pattern.
6. Give the maintenance note: the one or two segments most likely to need loosening later, and how to change them safely.
</task>
<output_format>
The rule sentence — the pattern in a code block — piece-by-piece table — verification table — edge cases with [CONFIRM] flags — warnings and maintenance.
</output_format>
Rules:
- The pattern must be consistent with EVERY example given; never silently drop an inconvenient one.
- Flavour honesty: if my stated environment lacks a feature the clean solution needs (e.g. lookbehind), say so and give the workaround that runs there.
- Prefer readable patterns over golf; include the verbose or commented form where the flavour supports it.
Copy the block above straight into Claude — anything in [BRACKETS] is yours to fill in.
Want it tuned to your business? Bring it to the free weekly call and we'll adapt it live.
Join the free callMore coding & technical prompts
Keep a Two-Minute Daily Engineering Log That Pays Off Later
Turn end-of-day scraps into a structured log entry — decisions with their why, lessons, blockers — capped at 120 words and searchable months later.
Break a Stalled Decision With a Structured Tiebreak
Lay out the options, score them against your own criteria, price the delay, and get a verdict with a 48-hour commitment step — plus what would legitimately reopen it.
Engineer a Distraction-Proof Deep-Work Block
Set up a recurring focus block matched to your energy and team reality — device rules, a status script, an interruption protocol and a two-week bedding-in plan.