Home / Tools / Regex tester

Regex tester

Test regular expressions live. Matches are highlighted as you type, with capture groups and a replace preview. Uses JavaScript's regex engine.

  • Code tool
  • Runs in your browser
  • Tested 19 November 2026
  • Sources
//

Regex cheat sheet

PatternMatches
.Any character except a newline (add the s flag to include newlines)
\d   \w   \sA digit, a word character (letter, digit or underscore), whitespace
\D   \W   \SThe opposite of each of the above
[abc]   [^abc]Any one of a, b or c; any character except those
[a-z]Any character in the range a to z
^   $Start and end of the text (or of each line with the m flag)
\bA word boundary
*   +   ?Zero or more, one or more, zero or one
{3}   {2,5}   {2,}Exactly 3, between 2 and 5, 2 or more
*?   +?"Lazy" versions that match as little as possible
(abc)A capture group, reusable as $1 in replacements or \1 in the pattern
(?:abc)A group that doesn't capture
(?<name>abc)A named capture group
a|ba or b
\.   \*A literal dot or star. Put a backslash before any special character to match it literally

Flags

  • g global: find every match, not just the first.
  • i ignore case: cat also matches "Cat" and "CAT".
  • m multiline: ^ and $ match at the start and end of each line.
  • s dot all: . also matches newlines.
  • u unicode: treat the pattern as Unicode, needed for some emoji and \p{…} classes.

Regex flavours differ

This tester uses JavaScript's regex engine, the one built into every browser and Node.js. Python, PHP, Java and other languages support almost all of the same core syntax, but differ in details. For example, Python writes named groups as (?P<name>…) and uses \1 rather than $1 in replacements. Check your language's documentation for advanced features.

Watch out for slow patterns. Nested repeats like (a+)+ can take an extremely long time on text that almost matches, a problem called catastrophic backtracking. This tester stops any pattern that runs for more than a second.

Sources

Where the formulas and figures on this page come from. We test every tool against worked examples from these before publishing.