How to use
Use this to generate a practical Python regex without guessing escaping or counts.
- Pick From examples (generalize digits/whitespace) or Escape literal (match the exact text).
- Paste input lines (one example per line) into the box.
- Choose options like Flexible counts (e.g.,
\d+) or Exact counts (e.g.,\d{5}), and whether to add ^...$ anchors. - Click Generate, then copy the pattern or the Python snippet.
FAQ
Is the generated pattern compatible with Python re?
Yes—output is designed for Python re (e.g., \d, \s, ^...$) and includes a re.compile snippet.
What does “Flexible runs (+)” do?
It turns repeated classes into + (e.g., 12345 → \d+) instead of exact counts like \d{5}.
Why use ^ and $ anchors?
Anchors force the whole line to match. Without them, the regex can match a substring inside a longer string.
How do I match a literal dot, plus, or parentheses?
Use Escape literal mode; it automatically escapes regex metacharacters like ., +, and (/).
Can I generate a single regex from multiple example lines?
Yes—From examples combines lines using alternation: (?:pat1|pat2|...).
Do the flags map to Python flags?
Yes: IGNORECASE → re.IGNORECASE, MULTILINE → re.MULTILINE, DOTALL → re.DOTALL.
Why might the “quick check” differ from Python?
The quick check runs in your browser’s JavaScript regex engine; most basics match Python closely, but some edge behaviors can differ.