JavaScript Regex Tester

Write a regular expression and see every match highlighted as you type, with a table of capture groups and a live preview of replacements. It uses the JavaScript regex engine of your browser.

Flags

Matches highlighted

Runs entirely in your browser. Nothing you enter is uploaded or stored.

How to use the regex tester

Enter a pattern without the surrounding slashes, choose flags and type or paste a test string. Matches are highlighted as you type, and the table below lists each match with its position and capture groups, including named groups such as (?<year>\d{4}). The Replace with field shows what String.prototype.replace would return, with $1, $<name>, $& and $$ working exactly as in JavaScript. Without the g flag only the first match is found and replaced.

The tester runs your browser's own RegExp engine in a background worker, so results match what your JavaScript code will do. Some patterns, such as (a+)+$, can take exponential time on certain input (catastrophic backtracking). If a run takes longer than one second, the worker is stopped and you get a warning instead of a frozen tab. To keep things responsive, the test string is limited to 100,000 characters and the first 1,000 matches are shown.

Worked example

The default pattern (\d{4})-(\d{2})-(\d{2}) with the g flag finds three ISO dates in the sample text. Group 1 is the year, group 2 the month and group 3 the day. The replacement $3.$2.$1 rewrites 2026-10-17 as 17.10.2026. With named groups, (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2}) and the replacement $<d>.$<m>.$<y> do the same and are easier to read.

Regex cheat sheet

PatternMeaning
.Any character except line breaks (with s: any character)
\d \w \sDigit, word character [A-Za-z0-9_], whitespace
\D \W \SThe opposite of each of the above
[abc] [^abc] [a-z]One of, none of, a range
^ $Start and end of input (with m: of each line)
\bWord boundary
* + ? {2,5}0 or more, 1 or more, optional, between 2 and 5
*? +?Lazy versions: match as little as possible
(…) (?:…) (?<n>…)Capture group, non-capturing group, named group
a|bEither a or b
(?=…) (?!…)Followed by, not followed by (lookahead)
(?<=…) (?<!…)Preceded by, not preceded by (lookbehind)
\1 \k<n>Back-reference to group 1 or to a named group
\p{L}Any Unicode letter (needs the u flag)

Common mistakes

  • Forgetting to escape special characters. To match a literal dot, question mark or parenthesis write \., \? or \(. In a JavaScript string passed to new RegExp(), backslashes must be doubled: "\\d+".
  • Greedy quantifiers. <.+> matches from the first < to the last > on the line. Use <.+?> or <[^>]+>.
  • Missing anchors in validation. \d{5} also matches inside 123456. Use ^\d{5}$ to require the whole input to match.
  • Reusing a global regex with test(). A regex with the g flag remembers lastIndex, so calling test() twice on the same string can return true and then false.
  • Nested quantifiers. Patterns like (\w+)* or (a|a)+ can backtrack catastrophically. Make alternatives mutually exclusive and avoid quantifying a group that is itself quantified.

Frequently asked questions

Which regex flavour does this tester use?

It uses the JavaScript RegExp engine built into your browser, the same one used by Node.js in the case of Chrome's V8. Features such as lookbehind, named groups and Unicode property escapes are supported in all current browsers.

Why is only one match found?

Without the g (global) flag, a JavaScript regex stops after the first match. Tick g to find and replace all matches.

How do I use capture groups in the replacement?

Write $1, $2 and so on for numbered groups, $<name> for named groups, $& for the whole match and $$ for a literal dollar sign. The replace preview shows the result immediately.

What is catastrophic backtracking?

Some patterns with nested or overlapping quantifiers, such as (a+)+$, make the engine try an exponential number of ways to match when the input almost matches. The tester stops any run that takes longer than one second, so your tab does not freeze.

Is my test data sent anywhere?

No. The pattern and text are processed by a worker script inside your browser. Nothing is uploaded, logged or stored.

How do I match a line break?

Use \n for a line feed, or \r?\n to also handle Windows line endings. With the s flag a dot matches line breaks as well, and with the m flag ^ and $ match at the start and end of each line.