All tools

Regex Tester

Testers

Test regular expressions in JavaScript and Python with the real engines: every match and group highlighted, replacements previewed, and the two flavours compared side by side.

  • JavaScript
  • Runs offline
  • Python
  • Regex
//gm
Flags
Matches
JavaScript code
const re = /^(?<level>INFO|WARN|ERROR) (?<time>\d{2}:\d{2}:\d{2}) (?<message>.*)$/gm;
const matches = [...text.matchAll(re)];

Two engines that look alike

JavaScript and Python regular expressions share most of their syntax and differ in the details that bite: how named groups are written, what \d and \w match, where $ stops, and features one has and the other lacks. This tester runs the real engines — your browser's for JavaScript and CPython's re module for Python — so a pattern that works here works in your code. Compare Both runs them side by side and shows where they disagree.

Regex cheat sheet

SyntaxMeaningJavaScriptPython
.Any character except a newlineWith s, newlines tooWith DOTALL, newlines too
\d \wDigit, word characterASCII onlyAny Unicode digit or letter; ASCII with re.ASCII
\s \bWhitespace, word boundarySame in both
^ $Start and end — of each line with m / MULTILINE$ is the very end$ also matches before a final newline; \Z is the very end
* + ? {2,5}Repeat; add ? to make it lazySame in both
(…) (?:…)Capturing and non-capturing groupSame in both
Named groupA group you can refer to by name(?<name>…), \k<name>(?P<name>…), (?P=name)
(?=…) (?!…)LookaheadSame in both
(?<=…) (?<!…)LookbehindAny lengthFixed width only
(?>…) a*+Atomic group, possessive quantifierNot supportedPython 3.11+
ReplacementRefer to a group in the replacement$1, $<name>, $&\1, \g<name>, \g<0>

How to use the regex tester

  1. Pick JavaScript or Python. Python loads its runtime the first time, which takes a few seconds.
  2. Type the pattern and toggle flags. Matches highlight in the text as you type; groups and their positions are listed on the right.
  3. Click a match in the list to select it in the text.
  4. Tick Replace With to preview a substitution, using the flavour's own group syntax.
  5. Press Copy Code for a ready-to-paste snippet with the pattern, flags and replacement filled in.

Examples

Parse log lines with named groups

Level, time and message as named groups, one match per line.

Reformat dates with a replacement

31/12/2026 to 2026-12-31 with three groups.

See where JavaScript and Python disagree

\d matches Arabic-Indic digits in Python but not in JavaScript.

Survive a runaway pattern

^(a+)+$ on a near-miss takes forever. The tester stops it instead of freezing.

Frequently asked questions

Why does my pattern work here but not in my code?

Usually the string literal, not the regex. In Python, write patterns as raw strings — r"\d+" — or every backslash has to be doubled. In JavaScript, a pattern built with new RegExp("…") needs doubled backslashes too; a /…/ literal does not. Copy Code gets this right for you.

Why did the tester stop with "took too long"?

Some patterns, like (a+)+, try exponentially many ways to match before giving up — catastrophic backtracking. In a server, one such input can tie up a process. Rewrite the pattern so no two parts can match the same text, or use an atomic group in Python 3.11+.

Why does \d match digits that are not 0–9 in Python?

In Python, \d on a str pattern matches any Unicode decimal digit, including Arabic-Indic and Devanagari ones. Use [0-9] or the ASCII flag when you mean only 0–9. In JavaScript, \d is always 0–9.

How do I match across several lines?

Two flags do different things. m / MULTILINE makes ^ and $ match at every line. s / DOTALL lets . match a newline, so .* can run past the end of a line.

Is my text sent anywhere?

No. Both engines run in your browser. Choosing Python downloads the Python runtime from jsDelivr once; nothing you type is sent.

Related tools

Learn more