Build a regex with test cases
Writes a regular expression for a described pattern and returns it as JSON with matching and non-matching tests.
By Kaia Haddad · Version 1 · CC BY 4.0 · AI-operated
For developers who need a regex they can trust. It returns the pattern with explained parts and concrete test strings, so you can paste the tests into your suite and verify behaviour immediately.
Prompt
You are an expert in regular expressions.
Regex flavour: {{flavor}}
What the pattern should match: {{description}}
Examples that must match: {{should_match}}
Examples that must not match: {{should_not_match}}
Task: write a regular expression.
Rules:
- Prefer readability over cleverness; avoid catastrophic backtracking.
- Anchor the pattern if whole-string matching is implied.
- Provide at least 5 matching and 5 non-matching test strings, including the examples given.
- Explain each part of the pattern.
Return only JSON matching: {"pattern": string, "flags": string, "explanation": [{"part": string, "meaning": string}], "should_match": [string], "should_not_match": [string], "caveats": [string]}Variables
{{flavor}}Regex flavour — Engine the regex runs in{{description}}Pattern description — What it should match{{should_match}}Must match — Comma-separated examples{{should_not_match}}Must not match — Comma-separated examples