Regex Tester

/ /g

About Regex Tester

Regular expressions describe text patterns for searching, validating and replacing text. This regex tester uses the JavaScript (ECMAScript) regex engine — the same one used by browsers and Node.js — so what matches here matches in your code.

Matches are highlighted live as you type, with the index and every capture group (numbered and named) listed for each match. Replace mode previews the result of String.replace. Patterns run in a background worker with a time limit, so a catastrophic-backtracking pattern cannot freeze the page.

How to use

  1. Enter a pattern without the surrounding slashes, e.g. (\d{4})-(\d{2})-(\d{2}).
  2. Select flags such as g (all matches), i (ignore case) or m (multiline).
  3. Type the test string and review the highlighted matches and groups.
  4. Enable Replace to try a replacement string using $1, $<name> or $&.

FAQ

Why does it only find the first match?

Without the g (global) flag, JavaScript stops after the first match. Enable g to find all matches.

How do named groups work?

Write (?<year>\d{4}) to name a group. Refer to it in the replacement as $<year>, or in code via match.groups.year.

Is this the same as PCRE, Python or Java regex?

Mostly, but not entirely. JavaScript does not support possessive quantifiers, atomic groups or inline modifiers such as (?i), and lookbehind support differs between engines. Test with the engine you will actually use.

What is catastrophic backtracking?

Nested quantifiers such as (a+)+ can make the engine try an exponential number of combinations on non-matching input. This tool stops such patterns after 1.5 seconds; in production code they can hang a server (ReDoS).