Regex Tester

Test JavaScript regular expressions live: highlight every match, see capture groups and named groups, toggle flags and preview replacements in your browser.

/ /g
Flags

Matches

No matches

# Position Match Groups

Replace

What is a regular expression?

A regular expression (regex) is a pattern that describes text, such as "four digits, a hyphen, two digits". Developers use it to validate input, search logs, extract values and replace text in bulk. This tester uses your browser's JavaScript engine, so the results match what String.prototype.match and replace return in browsers and Node.js.

How to use

  1. Type the pattern without the surrounding slashes, and tick the flags you need.
  2. Paste the text to test. Every match is highlighted, in alternating colors so neighboring matches stay distinguishable.
  3. The table lists each match with its position and capture groups. Click a row to select that match in the text.
  4. Fill in "Replace with" to preview the result. Use $1, $<name> for groups and $& for the whole match.

Example: reformat dates

The pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) finds dates such as 2024-03-15 and names the three parts. Replacing with $<day>/$<month>/$<year> gives:

15/03/2024

Quick reference

SyntaxMeaning
\dA digit 0-9
\wA letter, digit or underscore
\sWhitespace: space, tab, line break
.Any character except a line break (with s: any character)
* + ?0 or more, 1 or more, 0 or 1
{2,4}Between 2 and 4 times
^ $Start and end of the text (with m: of each line)
\bWord boundary
[abc] [^abc]One of a, b, c / anything except them
a|ba or b
(...)Capture group: $1, $2 in the replacement
(?:...)Group without capturing
(?<name>...)Named group: $<name> in the replacement
(?=...) (?!...)Followed by / not followed by (lookahead)

FAQ

Which regex flavor does this use?

JavaScript (ECMAScript), the same as browsers and Node.js. Most syntax also works in Java, Python, PHP and Go, but there are differences: Python writes named groups as (?P<name>...), and inline flags such as (?i) at the start of a pattern are not supported here; use the flag checkboxes instead.

Why did the test stop with a timeout?

Some patterns, especially nested quantifiers like (a+)+$, make the engine try an enormous number of combinations ("catastrophic backtracking"). The tester runs in the background and stops after 2 seconds so the page stays responsive. Rewrite the pattern to avoid nested repetition; the same pattern could freeze your server too.

Do I need double backslashes?

Not here: type \d directly. When you copy the pattern into a string in Java, C# or JavaScript code (not a /.../ literal), each backslash must be written twice, as in "\\d{4}".

Is my text sent to a server?

No. Matching and replacing happen entirely in your browser, so you can safely test patterns against logs or data that should not leave your computer.