Python Regex Tester Online - Test & Debug Regular Expressions
Test Python regular expressions online in real-time. Debug regex patterns with match highlighting, group capture, and Python flag support.
About
Regular expressions in Python's re module use a syntax that diverges from other flavors in subtle but critical ways. A pattern that works in JavaScript or PCRE may silently fail in Python due to differences in named group syntax ((?P<name>...) vs (?<name>...)), flag handling, or Unicode defaults. Mismatched regex between environments is a common source of data extraction bugs that pass unit tests but fail on edge-case production input. This tool interprets Python-flavored regex patterns and maps them to equivalent execution, showing all matches, captured groups, and positional data against your test string in real time.
The tester supports Python's standard flags: re.IGNORECASE, re.MULTILINE, re.DOTALL, and re.VERBOSE. It translates Python-specific constructs like (?P<name>...) named groups and (?P=name) backreferences into executable form. Note: this tool approximates Python regex behavior using a translation layer. Lookbehind width restrictions and certain Unicode property escapes (\p{...}) may differ from CPython's re module. For production validation, always confirm against the actual Python interpreter.
Formulas
Python regex matching follows a deterministic process. The re module compiles a pattern string into an internal automaton, then executes it against the target string.
Each matchi contains positional data: start (inclusive index), end (exclusive index), and the matched substring string[start:end]. For patterns with groups, each match returns a tuple of captured groups rather than the full match.
Python-to-JS syntax translation follows these rules: (?P<name>...) → (?<name>...) (named group), (?P=name) → \k<name> (backreference). The re.VERBOSE flag strips unescaped whitespace and # comments before compilation.
Reference Data
| Python Flag | Short Form | Inline | Effect |
|---|---|---|---|
| re.IGNORECASE | re.I | (?i) | Case-insensitive matching for ASCII and Unicode |
| re.MULTILINE | re.M | (?m) | ^ and $ match at line boundaries |
| re.DOTALL | re.S | (?s) | . matches any character including \n |
| re.VERBOSE | re.X | (?x) | Allows whitespace and comments in pattern |
| re.ASCII | re.A | (?a) | ASCII-only matching for \w, \b, \d, \s |
| re.UNICODE | re.U | (?u) | Unicode matching (default in Python 3) |
| Common Python Regex Constructs | |||
| (?P<name>...) | Named capturing group (Python syntax) | ||
| (?P=name) | Backreference to named group | ||
| (?:...) | Non-capturing group | ||
| (?=...) | Positive lookahead | ||
| (?!...) | Negative lookahead | ||
| (?<=...) | Positive lookbehind (fixed-width in Python) | ||
| (?<!...) | Negative lookbehind (fixed-width in Python) | ||
| (?(id)yes|no) | Conditional pattern (if group matched) | ||
| \A | Start of string (not affected by MULTILINE) | ||
| \Z | End of string (not affected by MULTILINE) | ||
| \b | Word boundary | ||
| \B | Non-word boundary | ||
| \d / \D | Digit / Non-digit (Unicode-aware by default) | ||
| \w / \W | Word char / Non-word char (Unicode-aware) | ||
| \s / \S | Whitespace / Non-whitespace | ||
| {m,n} | Between m and n repetitions | ||
| {m,n}? | Non-greedy (lazy) repetition | ||
| [^...] | Negated character class | ||