How to use the regex tester
- Type a pattern in the Regular expression box, without the surrounding slashes.
- Turn flags on or off. The flag string appears next to the pattern, so you can copy
/pattern/flagsstraight into your code. - Edit the Test string. Matches are highlighted as you type, with a count at the top.
- Check Match details for each match's position and capture groups (
$1,$2) and named groups. - Optionally enter a Replace with value to preview the result of
string.replace(). Use$1for a numbered group,$<name>for a named group, and$&for the whole match.
The tester uses your browser's JavaScript regular expression engine, so the results are exactly what RegExp in Chrome, Firefox, Safari, or Node.js would give you.
Flags explained
- g (global) finds every match instead of stopping after the first.
- i (ignore case) makes
amatchA. - m (multiline) makes
^and$match at the start and end of each line, not only the whole text. - s (dotAll) lets
.match line breaks too. - u (unicode) treats emoji and other characters outside the Basic Multilingual Plane as single characters and enables
\p{...}classes such as\p{L}for any letter.
Quick reference
\ddigit,\wletter, digit, or underscore,\swhitespace. Uppercase versions (\D,\W,\S) mean the opposite..any character except a line break (unless thesflag is on).[abc]one of a, b, or c.[^abc]any character except those.*zero or more,+one or more,?zero or one,{2,5}between 2 and 5.- Add
?after a quantifier to make it lazy:.*?matches as little as possible. ^start,$end,\bword boundary.(…)capture group,(?:…)group without capturing,(?<name>…)named group.(?=…)followed by,(?!…)not followed by,(?<=…)preceded by.
Example
To find dates written as 2026-10-26 and swap them to 26/10/2026:
- Pattern:
(\d{4})-(\d{2})-(\d{2}) - Replace with:
$3/$2/$1
Add \b at both ends if the dates may be next to other digits.
Common mistakes
- Greedy matching.
<.+>on<b>bold</b>matches the whole string. Use<.+?>or<[^>]+>to match each tag. - Forgetting to escape.
.,?,+,(, and[are special. To match a literal dot, write\.. - Different engines. Python, PHP (PCRE), Java, and .NET support mostly the same syntax, but lookbehind, possessive quantifiers, and Unicode classes vary. Test in your target language before shipping.
- Catastrophic backtracking. Nested quantifiers like
(a+)+can freeze the engine on long input. Make each repetition match a clearly different thing.
For a longer introduction, read the in-depth regex guide linked on this page.