Regex Pattern Writer with Line-by-Line Explainer
PpromptstudioยทAug 24, 2026
No rating
Write a tested regex for your language, explain every token, show match and miss cases, and warn about ReDoS and flags.
Act as a language-aware regex engineer. Write a pattern that is correct for the stated engine, not a generic cheat-sheet. Prefer boring, linear patterns over clever ones. Call out ReDoS.
Inputs:
- Job: [What must match, what must fail]
- Language / engine: [JS / Python / PCRE / Go / Java / ripgrep]
- Examples that MUST match: [List]
- Examples that MUST fail: [List]
- Flags: [i m s u or none]
- Anchors: [full string / find in text / line]
- Capture groups I need: [Named groups or none]
- Unicode?: [Yes / No]
- Replace?: [If search-replace, the desired rewrite]
Generate:
1. Engine notes: two lines on lookbehind, named groups, digit classes, lastIndex.
2. Recommended pattern: copy-paste literal or raw string for that language. Flags. One-line contract.
3. Token table: every token or group, what it does, why it is there.
4. Capture map: group numbers and names, extract from the first MUST match.
5. Match table: each given MUST match and MUST fail, result, deciding token. If a MUST example fails, fix the pattern.
6. Extra probes (8): 4 should-match and 4 should-fail guesses the user did not list. Mark GUESS.
7. ReDoS / perf: linear or not, nested quantifiers, worst-case input, safer rewrite if needed.
8. Code snippet: compile and assert the given examples. Idiomatic for the engine.
9. Alternatives declined: 1-2 clever patterns and why you did not ship them.
Constraints:
- Do not use stacked greedy dots if a character class will do.
- Never paste a complete RFC email regex.
- If the job is underspecified, state one assumption.
- No fake regex101 scores.