Regex Tester – JavaScript Regular Expressions

Write a JavaScript regular expression, see every match highlighted as you type, inspect groups, and preview a replacement.

Loading tool…

About the Regex Tester

Patterns run on your browser's own RegExp engine, so the results are exactly what str.match(), matchAll() and replace() return in JavaScript and Node.js. Other engines differ: PCRE (PHP), Python re and .NET support features like possessive quantifiers or inline modifiers that JavaScript does not.

Flags: g finds all matches, not just the first; i ignores case; m makes ^ and $ match at each line; s lets . match newlines; u enables full Unicode and \p{…} property escapes; y (sticky) only matches at lastIndex. The match table shows each match's index range, numbered groups and named groups from (?<name>…). The replace preview supports $1, $<name>, $& and $$.

Matching runs in a Web Worker with a 1.5-second limit and stops after 5,000 matches, so a pattern with catastrophic backtracking such as (a+)+$ is stopped with a message instead of freezing the tab. Invalid patterns are reported with the engine's own error message.

How to use it

  1. Enter the pattern without slashes.
  2. Tick the flags you need (g, i, m, s, u, y).
  3. Paste the test string and check the highlighted matches and the group table.
  4. Type a replacement to preview and copy the result.

Frequently asked questions

Why does my regex only find one match?
Without the g flag, JavaScript stops at the first match. Tick g to find all matches.
How do I use a capture group in the replacement?
Write $1, $2… for numbered groups or $<name> for named groups. $& inserts the whole match and $$ a literal dollar sign.
What is catastrophic backtracking?
Nested or overlapping quantifiers like (a+)+ or (\w|\d)* make the engine try exponentially many paths on non-matching input. Make the pattern more specific or remove the nesting.
Do I need to escape slashes?
Not here: enter the pattern without delimiters. In a JavaScript regex literal, escape / as \/; Copy as /…/flags does that for you.

Related tools