Regex aus Beispielen bauen

Erzeugt eine Regex aus positiven und negativen Beispielen - mit Erklärung und Test-Strategie.

Zuletzt geprüft 23. April 2026

Prompt

Build a regex from examples. Input:
- Should match: [LIST]
- Must NOT match: [LIST]
- Target flavor: [PCRE / JAVASCRIPT / PYTHON / POSIX]
- Where it's used: [EXTRACT / VALIDATE / REPLACE]

Output:
1. REGEX - the pattern. On its own line.
2. READABLE BREAKDOWN - pattern piece by piece, each with what it matches
3. TRADEOFFS - if a tighter pattern would reject edge cases, say so
4. TEST CASES - 5 additional strings the regex should match + 5 it should reject, including tricky edges (empty, near-miss, unicode if relevant)
5. ANCHOR DECISION - ^ / $ / \b - state whether and why

Rules:
- Prefer readability. If a regex crosses ~80 chars, offer a verbose mode (extended whitespace) version.
- Do not use greedy `.*` without a reason - prefer specific classes or non-greedy
- No lookaround unless needed
- For validation use cases: explicit anchors. For extraction: usually not.
- Warn about common pitfalls (email regex is a trap, date parsing, multiline)

Negative examples:
[PASTE]

Positive examples:
[PASTE]

Wann nutzen

Wenn du eine Regex brauchst und dir klar ist, dass handgeklopfte Patterns Edge-Cases verfehlen. Die Testfälle sind das Wertvolle - nimm sie in die Tests mit auf.

Use-Cases

  • Log-Parsing: Zeilen in Feldern extrahieren.
  • Formular-Validierung (mit Vorbehalt - siehe Warnung).
  • Batch-Rename / sed-Ersetzung auf großer Datei.

Getestet mit

Bei Sprachen wie JS ohne x-Flag wird die Verbose-Version unpraktisch. Dann: Regex mit Kommentaren als Block darüber im Code dokumentieren.