Regex & pattern matching

Python regex testerinspect the actual re result

Run a Python pattern against text, inspect captures, or preview a re.subn replacement. Execution starts only when you test.

Python regex tester

Pattern

Test text

Result

Ready for input or a manual test.

Pattern and test text stay in this browser. Python runtime files load only on the first run.

Options

Use i, m, s, x, a once each; there is no JavaScript g flag.
  • i — Ignore case
  • m — ^ and $ match line boundaries
  • s — Dot matches newline
  • x — Verbose pattern with whitespace/comments
  • a — ASCII character classes

Python runtime: loads on first test

Limits: pattern 2,000; text 100,000; replacement 10,000 UTF-16 units; 10,000 matches; 1,000,000 output and 4,000,000 report units. A run exceeding 2 seconds is terminated.

Ready for input or a manual test.

A pattern can pass in a JavaScript tester and fail in Python code. This Python regex tester runs CPython re itself, so named groups, flags and replacement backreferences follow the runtime you use.

Use this Python regular expression tester to compare finditer, search and fullmatch. A Python re tester is especially useful when a Python regex substitution must preserve captured fields rather than JS-style $1 tokens.

Why use this Python regex tester

See every captured span

The Python regex tester shows group zero beside numbered and named groups. A group that did not participate stays null with span (-1, -1), while an empty capture remains an empty string. The distinction matters before extracting fields.

One highlighted whole match contains two colored captures linked to separate result cards.

Preview Python replacement without changing input

Try a template such as \g<last>, \g<first>. CPython expands the named groups and shows the new string separately; the source text remains available to inspect. A zero replacement count means every match may be replaced.

Two colored captured segments swap order in a separate preview while the original strip remains intact.

Test the semantics that usually surprise you

01

Choose the Python operation

finditer lists non-overlapping matches. search stops at the first hit; fullmatch requires the entire text. There is no JavaScript g flag, and changing the operation makes an old report stale.

02

Set flags before the manual run

The i, m, s, x and a flags map to CPython re. m changes ^ and $ at line boundaries; s lets a dot cross a newline. Loading the Python runtime begins on your first explicit run.

03

Inspect spans before export

Group spans use zero-based Python Unicode code points, not browser UTF-16 offsets. On A😀B, B starts at Python index 2. Ctrl/Cmd + Enter reruns; editing disables export until a fresh result arrives.

What the result actually contains

Real Python re engine

This Python regex tester loads CPython through Pyodide in a Worker and displays its actual Python version. It does not relabel JavaScript RegExp as Python.

Groups and exact positions

Each match includes group zero, numbered groups, names, values and end-exclusive spans. The browser highlight converts code-point offsets so an emoji does not shift the selected text.

Replacement with Python syntax

The Python regex substitution mode uses re.subn. Templates accept \1 and \g<name>; an empty template deletes matches, while $1 remains literal text.

Complete bounded report

Copy or download JSON only after a finished run. The report records operation, flags, pattern, input, runtime and every returned match; replacement mode can also export text.

Boundaries of this Python re run

One engine only
The Python regex tester runs Unicode text through CPython re. It does not execute PCRE2, JavaScript or the third-party Python regex package; patterns for those engines can mean something different.
No automatic execution
A potentially expensive expression runs only after Test or Ctrl/Cmd + Enter. The 2-second budget starts after Python loads; timeout terminates its Worker rather than treating a partial run as no match.
Python flags, not JavaScript flags
Use i, m, s, x and a at most once each. There is no g, u or y toggle: finditer controls all-match behavior and Python string patterns are Unicode by default.
Finite input and output
Pattern, text and template limits are 2,000, 100,000 and 10,000 UTF-16 units. More than 10,000 matches, a million output units or a four-million-unit report fails the whole run.
No code or remote text source
Only fixed Python re operations execute. The tool never runs a pasted Python program, imports a file, fetches a URL or puts private test text into a shareable link.
Preview is not an edit
re.subn produces a separate output. Example and Clear are the only controls that replace the current inputs; each requires a preview and offers one undo.

Python regex tester questions

Why does a pattern work in regex101 but fail in Python?

Check the selected engine. regex101 can default to PCRE2; this page runs CPython re. For example Python names a group with (?P<name>...), while some other engines accept (?<name>...).

Can I test a Python re.sub replacement here?

Yes. Choose Replacement, enter the template and run. \g<name> and \1 use Python rules; $1 is not expanded. The output is a preview and the original text stays unchanged.

Can I visualize Python regex matches and groups online?

Yes. The result highlights each match and lists group values and spans. Zero-width matches receive a visible marker. Python runs locally in a Worker after its runtime assets load.

When is .*? safer than .*?

The lazy quantifier tries the shortest viable span; greedy .* tries the longest. Neither guarantees a safe runtime. Test both on representative text, and stop a long run if needed.

What is the difference between (...) and (?:...)?

Both group pattern parts. Only (...) creates a numbered capture and can appear in the group list or a replacement backreference; (?:...) groups without taking a number.

Still have a question?

Try the Python regex tester on a real edge case

Compare a passing and failing sample, then inspect captures and the actual Python version before copying the report.