---
name: regex-pattern-generator-explainer
description: "Builds the regex you describe and then teaches it back: a plain-English walkthrough of every class, quantifier, group, and lookaround, plus matching and non-matching examples, so the whole team can maintain it. Use when someone needs a regex written and then explained token by token with examples, so a team that does not read regex can maintain it. Do not use for formatting an existing pattern with comments, or optimising one for speed. Related topics: coding, utility, data."
---

# Regex Pattern Generator & Explainer

Builds the regex you describe and then teaches it back: a plain-English walkthrough of every class, quantifier, group, and lookaround, plus matching and non-matching examples, so the whole team can maintain it.

## When to use

Use this skill when someone needs a regex written and then explained token by token with examples, so a team that does not read regex can maintain it. Do not use it for formatting an existing pattern with comments, or optimising one for speed.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Write the simplest pattern that meets the description in the chosen flavor and name any flavor feature it depends on.
3. Explain the pattern left to right in a numbered list, one entry per token or group, giving what it matches and why it is there.
4. Name each capture group and state what a program would read from it.
5. When examples are requested, list four matches and four non-matches, pointing at the token that rejects each non-match.
6. Close with the most likely future change and show the edit that makes it.

## Inputs

- **What to match** (longer free text)
- **Language or flavor** (choose one: JavaScript, Python, PCRE (PHP), Java, Go)
- **Case insensitive** (choose one: Yes, No)
- **Show matches and non-matches** (choose one: Yes, No)
- **Explain these elements** (choose any: Character classes, Quantifiers, Capture Groups, Lookaheads/Lookbehinds)

## Output

A code block with the pattern, a numbered token-by-token walkthrough, an optional table of matching and non-matching examples with reasons, and a closing note on the most likely edit.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Regex Builder and Explainer

Build this regex and explain how it works.

- What to match: {{What to match}}
- Language or flavor: {{Language or flavor}}
- Case insensitive: {{Case insensitive}}
- Show matches and non-matches: {{Show matches and non-matches}}
- Explain these elements: {{Explain these elements}}

Write the simplest pattern that does the job in the chosen flavor, and say which flavor features it relies on (Go has no lookarounds, Java doubles backslashes in string literals, JavaScript needs the u flag for Unicode classes). Then explain the pattern left to right in a numbered list, one entry per token or group, each giving the token, what it matches, and why it is there. Spend the most words on the selected elements and keep the rest to a line each. Name each capture group and say what a program would read from it. When examples are requested, give four strings that match and four that do not, and for each non-match point at the token that rejects it. Finish with the one change most likely to be needed later (a different domain, an optional prefix) and show how to make it.

Return the pattern in a code block, the numbered walkthrough, the examples table when requested, and a closing note on the most likely future change.

## Pitfalls

- Using a lookbehind for Go or a Unicode class in JavaScript without the u flag, so the pattern fails to compile in the chosen flavor.
- Explaining the regex syntax in the abstract instead of what each token does for this specific input.
- Giving non-matching examples without saying which token rejects them, which is the part that teaches.
