Back to prompts
Coding & DevelopmentPremiumintermediate
4.7

Build Complex Regex Patterns From Plain English

Describe what you want to match in plain language and get a tested, explained regex pattern back.

Copy & Paste this prompt
You are a regex expert who writes precise, readable patterns.

I need a regex that: [DESCRIBE IN PLAIN ENGLISH WHAT TO MATCH]

Language/Engine: [JavaScript / Python / Go / Java / PCRE]

Examples that SHOULD match:
- [EXAMPLE 1]
- [EXAMPLE 2]
- [EXAMPLE 3]

Examples that should NOT match:
- [COUNTER-EXAMPLE 1]
- [COUNTER-EXAMPLE 2]

Provide:

1. THE REGEX — the final pattern, ready to copy-paste

2. EXPLAINED — break down every part of the pattern with inline comments. Use the verbose/extended format if the language supports it.

3. EDGE CASES — list 5 tricky inputs and whether they match or not, explaining why

4. PERFORMANCE NOTE — is this pattern susceptible to catastrophic backtracking? If so, provide a safer alternative.

5. CODE SNIPPET — a ready-to-use function in [LANGUAGE] that uses this regex with proper error handling

6. TEST CASES — 5 unit tests covering normal matches, edge cases, and non-matches
#coding#development#build#complex#regex

Works with

chatgptclaudegeminicopilot

💡 Pro Tips

  • Always provide both matching AND non-matching examples for precise results
  • Specify your regex engine — JavaScript and Python handle groups differently
  • Ask for the verbose/commented version to understand complex patterns later

✨ Example Output

**Request:** Match email addresses but reject ones with plus-addressing

**Regex:** `^[a-zA-Z0-9._%\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`
(Note: excludes `+` from local part)

**Explained:**
- `^` — start of string
- `[a-zA-Z0-9._%\-]+` — local part: letters, digits, dots, underscores, percent, hyphens (no plus)
- `@` — literal @ separator
- `[a-zA-Z0-9.\-]+` — domain: letters, digits, dots, hyphens
- `\.` — literal dot before TLD
- `[a-zA-Z]{2,}$` — TLD: 2+ letters

**Edge Case:** `user+tag@gmail.com` → ❌ No match (plus-addressing rejected)