Build and explain a regular expression
Writes a regex from plain-English rules plus examples that should and should not match, then explains each part.
Write a {{FLAVOUR}} regular expression.
Goal: {{GOAL}}
Should match:
{{MATCH_EXAMPLES}}
Should NOT match:
{{NO_MATCH_EXAMPLES}}
Return:
1. The pattern on its own line.
2. A breakdown of each part in plain English.
3. A table showing each example and whether the pattern matches it. Check carefully, one by one.
4. Any edge cases my examples do not cover that I should decide on.
Prefer a readable pattern over a clever one.Example output
Pattern: ^[A-Z]{2}\d{2} ?\d{4}$ Breakdown: two capital letters, two digits, optional space, four digits. Checked: 4 of 4 should-match pass, 3 of 3 should-not-match fail.
How to use
Give at least 3 examples in each list, including tricky near-misses. FLAVOUR is the engine, such as "JavaScript", "Python re" or "PCRE". Test the pattern in your own code or a regex tester before using it.
Why it works
Examples on both sides pin down exactly what you mean, which plain descriptions rarely do. The match table forces the model to check its own work, though you should still verify it because models do make regex mistakes.