Skip to content

Python Regex Tester — Test Python Regular Expressions Online

Free

Test Python regular expressions using re module syntax. Live match highlighting, named groups, flags. Free, browser-based.

python regex testtest python regex onlinepython re tester
All Developer Tools

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, \s match 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.VERBOSE flag allows comments inside patterns. JavaScript has no built-in equivalent.
  • ·Unicode: Python 3 matches Unicode by default; JavaScript requires the u flag.

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

1

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.

2

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.

3

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.

4

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.

Frequently asked questions

What is the difference between re.match() and re.search() in Python?+
re.match() only matches at the beginning of the string — it implicitly anchors to the start. re.search() scans through the string and returns the first match anywhere in it. If your pattern should match anywhere in the string, use re.search() or re.findall().
How do I use named groups in Python regex?+
Use (?P<name>...) syntax: r'(?P<year>\d{4})-(?P<month>\d{2})'. Access with match.group('year') or match.groupdict(). Back-references within the pattern use (?P=year). In re.sub() replacement strings, use \g<name>: re.sub(r'(?P<y>\d{4})', r'\g<y> AD', text).
What does re.VERBOSE do?+
re.VERBOSE (re.X) allows whitespace and # comments inside patterns. Unescaped spaces are ignored, and everything from # to end of line is treated as a comment. This lets you write long, documented regex patterns across multiple lines for maintainability.
How do I match Unicode characters in Python regex?+
Python 3 matches Unicode by default — \w matches any Unicode word character, \d matches any Unicode digit. To restrict to ASCII only, use the re.ASCII (re.A) flag. For specific Unicode categories, use \p{} syntax with the regex module (third-party, more powerful than the standard re module).
Why does my Python regex work in the tester but fail on my data?+
Common causes: the actual data has different line endings (\r\n vs \n — use re.MULTILINE and \r?\n), the data has encoding issues (ensure it is decoded to a Python str, not bytes), or the pattern uses re.match() when re.search() is needed. Test with a sample of your actual data, not a simplified string.

Related tools and guides