Regex tester

Test a regular expression as you type: matches are marked in your text, each with its position and its numbered and named groups, and a replacement shows the text after replacing. It uses JavaScript's own regular expressions, as in browsers and Node.js.

Flags

  • g: every match, not only the first
  • i: ignore case
  • m: ^ and $ match at the start and end of every line
  • s: . matches line breaks too
  • u: Unicode, for whole characters beyond the basic plane and classes such as \p{L} (any letter)

Quick reference

  • . any character except a line break
  • \d a digit, \w a letter, digit or underscore, \s white space; \D, \W and \S the opposite
  • [abc] one of a, b or c; [^abc] anything else; [a-z] a range
  • ^ the start, $ the end, \b a word boundary
  • * 0 or more, + 1 or more, ? 0 or 1, {2,5} 2 to 5; add ? to take as few as possible
  • (…) a group, $1 in a replacement; (?<name>…) a named group, $<name>; (?:…) a group that captures nothing
  • a|b either a or b
  • (?=…) followed by, (?!…) not followed by, (?<=…) preceded by, (?<!…) not preceded by

Replacements

$1, $2… put in numbered groups, $<name> a named one, $& the whole match and $$ a dollar sign. Without the g flag only the first match is replaced, as in JavaScript.

Patterns that hang

Nested repeats such as (a+)+ can take so long on text that almost matches that a program seems frozen: catastrophic backtracking. Each test here runs in the background and stops after one second, saying why.

Questions

Is this the same as PCRE, Python or Java regular expressions?

Mostly: the basics are shared, but each flavour differs at the edges. JavaScript has no possessive quantifiers or atomic groups and no \A or \Z anchors, for example. Test with the flavour your code uses.

Is my text uploaded?

No. The pattern and the text stay in your browser and are not saved; the test runs in a worker on your own device.

More tools