Regular expressions are powerful for finding phone numbers, emails or dates, but hard to get right first time. Matches are highlighted as you type, so you can iterate quickly.
A table shows what each capture group grabbed, and a replacement field with $1, $2 previews the substituted text. The default pattern masks the middle part of phone numbers.
How to use
- Enter a pattern and flags.
- Paste test text; matches turn yellow.
- Check groups in the table.
- Enter a replacement to preview the result.
Common tokens
\d digit, \w word character, \s whitespace, {n,m} repetition, + one or more, * zero or more, ? optional, ^ and $ line anchors.
Flags
g global, i case-insensitive, m multiline, s dot matches newline, u Unicode.
Worked examples
The default pattern (\d{3})-(\d{3,4})-(\d{4}) means three digits, dash, three or four digits, dash, four digits. Each pair of parentheses becomes a group, $1 to $3. With the replacement $1-****-$3, 555-123-4567 becomes 555-****-4567.
Reformatting dates works the same way: (\d{4})-(\d{2})-(\d{2}) replaced with $3/$2/$1 turns 2024-03-15 into 15/03/2024. $& inserts the whole match, and a named group (?<year>...) can be used as $<year>.
Common mistakes
A dot means “any character”, so 3.14 also matches 3x14. Escape it as 3\.14 to match a literal dot. Quantifiers are greedy, too: <.*> swallows all of <b>bold</b> in one go, while the lazy <.*?> matches each tag separately.
Highlighting always shows every match, but the replacement runs with exactly the flags you typed, so without g only the first match is replaced. Zero-length matches (from a pattern like a*) aren’t highlighted, and the tool lists up to 500 matches with the first 50 in the table.
FAQ
Is it the same as Python regex?
Mostly, but this uses the JavaScript engine, so some syntax differs, such as lookbehind support and named group syntax.
Do I need to double the backslashes?
Not here. Type the pattern as it would appear between slashes in /\d+/. You only double them when you build a pattern from a string in code, as in new RegExp("\\d+").