Regular Expression Tester

Type a pattern and flags, paste some test text: matches are highlighted in real time, with captured groups and a live replace preview.

Type a pattern to get started.

Mini regex cheat sheet
\d  \w  \sdigit, word character, whitespace (uppercase = negated)
.  ^  $any character, start of line, end of line
*  +  ?  {2,4}0+, 1+, 0 or 1, 2 to 4 repetitions
[abc]  [^abc]one of a, b, c β€” or none of them
(x)  (?:x)  (?<name>x)capturing group, non-capturing, named
a|b  \balternation, word boundary
(?=x)  (?!x)positive and negative lookahead
πŸ”’ Pattern and text stay in your browser: nothing is sent anywhere.

The most useful flags in JavaScript regexes

The g (global) flag finds all matches instead of just the first one; i makes the match case-insensitive; m makes ^ and $ apply to each line rather than the whole text; s lets the dot also match newlines; u enables proper Unicode handling (emoji, accented characters, classes like \p{L}). Flags combine freely: gim is one of the most common combinations. If you type an invalid or duplicate flag, this tester flags it right away.

Capturing groups and replacements

Parentheses capture parts of the match that you can reuse in the replacement: $1 is the first group, $2 the second, $& the whole match. With named groups, such as (?<year>\d{4}), you can write $<year>, which reads much better. A classic example: the pattern (\d{2})/(\d{2})/(\d{4}) with the replacement $3-$1-$2 converts dates from the US MM/DD/YYYY format to ISO format. Turn on replace mode above to see the preview update live.