Python Regex Tester — Test Python Regular Expressions Online
FreeTest Python regular expressions using re module syntax. Live match highlighting, named groups, flags. Free, browser-based.
What's next
Settings guide
Python `re` flags:
- ·`re.IGNORECASE` / `re.I` — Case-insensitive matching.
- ·`re.MULTILINE` / `re.M` —
^and$match at the start/end of each line, not just the whole string. - ·`re.DOTALL` / `re.S` —
.matches newlines. Without this,.skips\n. - ·`re.VERBOSE` / `re.X` — Ignores unescaped whitespace and treats
#as a comment character. Allows writing readable, commented regex patterns across multiple lines. - ·`re.ASCII` / `re.A` —
\w,\d,\smatch only ASCII characters. Without this flag, they match Unicode equivalents (the default in Python 3).
Python named groups: Use (?P<name>...) for named capture groups. Access with match.group('name') or match.groupdict(). Back-references use (?P=name).
Format comparison
Python re vs JavaScript RegExp — key differences:
- ·Named groups: Python uses
(?P<name>...), JavaScript uses(?<name>...) - ·Start anchor:
re.match()anchors to start;re.search()does not. JavaScript has no equivalent distinction — use^explicitly. - ·Verbose mode: Python's
re.VERBOSEflag allows comments inside patterns. JavaScript has no built-in equivalent. - ·Unicode: Python 3 matches Unicode by default; JavaScript requires the
uflag.
Online tester vs running Python locally: Testing regex in Python requires a script or REPL session. The online tester is faster for iterating on patterns, especially when working across a browser-based workflow without a Python environment handy.
How it works
Emulate Python re semantics
The regex is tested using an engine configured to match Python re behaviour: named group syntax, re.match() vs re.search() semantics, and flag mappings to Python's re constants.
Execute with selected flags
Flags are applied (IGNORECASE, MULTILINE, DOTALL, VERBOSE) and the pattern is run against the test string. All match positions, groups, and named group values are captured.
Highlight and annotate
Each match is highlighted in the test string. Groups are labelled by index and name (using Python's groupdict() naming). Non-matching regions remain unformatted.
Generate Python code
Ready-to-use Python code snippets are generated: re.findall(), re.search(), re.finditer(), and re.sub() calls using your exact pattern, flags, and test string. Copy directly into your script.
About this format
Python's `re` module has syntax and behaviour differences from JavaScript and other regex engines that matter when writing production data-processing code. Named groups use `(?P<name>...)` not `(?<name>...)`. The `re.match()` function anchors to the start of the string; `re.search()` searches anywhere. Verbose mode (`re.VERBOSE`) allows inline comments in long patterns.
Test your Python regex against a real string and see every match highlighted, groups labelled, and `re.findall()`, `re.search()`, and `re.sub()` code snippets generated for direct use in your script.