Raw view: Regex With Tests
No invisible, zero-width, or bidi-control characters detected.
Write a regular expression for the {{ENGINE}} engine (for example: PCRE2, JavaScript ES2018+, Python `re`, Go RE2, POSIX ERE) that implements the rule below. Engines differ on lookbehind, named groups, Unicode classes, and possessive quantifiers; use only features {{ENGINE}} supports, and say so if the rule needs a feature it lacks.
<rule>
{{RULE}}
</rule>
<should_match>
{{SHOULD_MATCH}}
</should_match>
<should_not_match>
{{SHOULD_NOT_MATCH}}
</should_not_match>
<usage>
{{USAGE}}
</usage>
<usage> says how the pattern will be applied: full-string validation, search within text, split, or capture-and-replace. This decides anchoring and grouping. If it is empty, assume full-string validation and anchor accordingly.
Process:
1. Restate <rule> as a list of atomic constraints ("starts with a letter", "3-16 characters total", "no consecutive hyphens"). Note any constraint that a regex handles badly (balanced parentheses, arithmetic, "valid date") and say whether you will approximate it or recommend code instead.
2. Build the pattern constraint by constraint. Prefer explicit character classes over `.`; prefer non-capturing groups `(?:...)` unless a group is meant to be extracted; prefer named groups for anything extracted when the engine supports them.
3. Check for catastrophic backtracking: nested quantifiers over overlapping classes (`(a+)+`, `(\w+\s?)*`). If present, restructure or state the risk and the input size at which it bites.
4. Run every string in <should_match> and <should_not_match> through the pattern mentally, character by character, and record the result. If any fails, fix the pattern before writing the answer; if a provided example contradicts <rule>, flag the contradiction rather than silently picking a side.
5. Add your own test cases for the edges the user did not supply: empty string, maximum length, boundary characters, Unicode if relevant, and the "almost valid" strings that differ by one character.
Where the rule has a well-known exact grammar (email per RFC 5322, URLs, IP addresses), state which simplification you are implementing. Full RFC compliance is almost never what the caller wants, and claiming it would be false.
## Output format
**Pattern** - one fenced code block containing only the pattern, plus the flags on the next line (for example `flags: i, u`). For a delimited literal, show it as the engine's language would write it.
**Breakdown** - a table: fragment, what it matches, which constraint from step 1 it implements. One row per fragment, in left-to-right order.
**Test table** - columns: input, expected, result, note. Include every provided example plus your additions from step 5. The "result" column must reflect your trace, not a guess; if you are unsure of one, mark it `verify`.
**Engine notes** - bullets on any feature that would differ in another common engine (lookbehind, `\p{L}`, `\Z` vs `$`), so the pattern can be ported.
**When not to use this** - one or two sentences on the inputs for which a parser or a few lines of code would be safer than this pattern.