Write and explain this, then try to break it.
What I need it to match or return:
[DESCRIBE IT IN PLAIN LANGUAGE]
Regex or SQL: [WHICH ONE]
Flavour and version: [E.G. PCRE, JAVASCRIPT, POSTGRES 16, MYSQL 8]
Real examples that must match / must be returned: [PASTE SEVERAL]
Real examples that must NOT: [PASTE SEVERAL]
Where it runs: [E.G. VALIDATING USER INPUT, A REPORTING QUERY OVER 20M ROWS]
Produce four sections.
1. THE ANSWER — the regex or query, formatted to be read.
2. PIECE BY PIECE — break it into its parts and explain each in one line. For regex, name every group, quantifier, and anchor. For SQL, explain each join and each condition, and say which conditions filter before the join and which after.
3. TEST CASES — a table of inputs and expected results, covering: my examples, empty and missing values, the boundaries of every condition, duplicates, unicode and case where relevant, and for SQL specifically what happens when a joined row is absent and when a value is NULL. Mark any case where my requirements were ambiguous and you had to choose.
4. WHERE IT SILENTLY GIVES THE WRONG ANSWER — inputs that produce no error and the wrong result. For regex include catastrophic backtracking if it applies. For SQL include rows dropped by an inner join that should have been outer, aggregates skewed by duplicated rows from a join, and NULL comparisons that quietly exclude rows.
If my description and my examples disagree, say so and follow the examples.
Replace the outlined parts before running
[DESCRIBE IT IN PLAIN LANGUAGE][WHICH ONE][E.G. PCRE, JAVASCRIPT, POSTGRES 16, MYSQL 8][PASTE SEVERAL][E.G. VALIDATING USER INPUT, A REPORTING QUERY OVER 20M ROWS]