Text 🔒 Runs in your browser — no data sent to servers

JavaScript Regex Tester

Test a pattern with the RegExp engine your JavaScript will run on, so what matches here matches in your code.

/ /
Test String
Matches & Groups
Matches appear here...

JavaScript Regex Tester

A regular expression that works in one language can fail in another, so the safest place to test a JavaScript pattern is a JavaScript engine. This page opens the Regex Tester with an example that uses named groups: the pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}), two dates in the test text, and the replacement $<day>/$<month>/$<year>, which rewrites them as day, month and year.

The engine is your browser's

Nothing is sent to a server: the pattern is compiled with new RegExp() in your own tab. That means V8 in Chrome and Edge, which is also the engine inside Node.js, SpiderMonkey in Firefox and JavaScriptCore in Safari. All three implement the same ECMAScript rules, so a pattern that behaves here behaves the same in your front-end or Node code on a current version.

The flags

FlagEffect
gFind every match, not only the first; needed to replace all of them
iIgnore letter case
m^ and $ match at every line break, not only at the ends of the text
s. also matches a line break
uUnicode mode: whole code points instead of UTF-16 units, and property escapes such as \p{L}
ySticky: match only where the previous match ended
dRecord the start and end of every group, for code that reads match.indices

Any other letter is dropped before the pattern reaches the engine, including the newer v flag. A letter typed twice, such as gg, is an error, and the tool shows the engine's own message.

What trips people up in JavaScript

  • \w and \b only know A to Z, a to z, 0 to 9 and the underscore, so they do not see é or Persian letters. With the u flag, \p{L} matches a letter in any alphabet.
  • Inside a string every backslash has to be doubled: new RegExp("\\d+") is the same pattern as the literal /\d+/. This tester takes the pattern the way you write it between slashes.
  • A regex with the g flag remembers lastIndex between calls to test() and exec(), so testing the same string twice can give true and then false.
  • replace() with a plain string as the pattern changes only the first occurrence; use a regex with g, or replaceAll().
  • In a replacement, $1 is the first group, $<name> a named one, $& the whole match and $$ a literal dollar sign.

Replace with named groups

The replacement box follows the same rules as String.prototype.replace(). With the example pattern, $<day>/$<month>/$<year> turns 2026-09-24 into 24/09/2026. Named groups also keep a pattern readable months later: match.groups.year says more than match[1].

Related pages

Start from a ready-made pattern with the URL regex, or fix doubled words with regex find and replace. For email addresses, and for numbers, phone numbers and IP addresses, the email regex guide and the guide to number, phone and IP patterns go into the details.

Guides