Flowfiles ← Regex Tester

Regex Replace Online

Live replacement preview · Backreferences $1 $<name> · Flags g i m — free, no signup

Test regular expression substitutions online with a live preview of the result. Enter your pattern, write your replacement string with backreferences, and see the output update instantly — before copying it to your JavaScript, Python, or shell code.

Switch to Replace mode and preview your substitution in real time.

Open Replace Mode →

Replacement string reference

PatternReplaced by
$&The full matched substring
$1, $2Numbered capture group (1-indexed)
$<name>Named capture group
$`Text before the match
$'Text after the match
$$Literal dollar sign

Common examples:

// Swap first and last name
'John Smith'.replace(/(\w+) (\w+)/, '$2, $1')
// → "Smith, John"

// Reformat date
'2024-03-15'.replace(/(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})/, '$<d>/$<m>/$<y>')
// → "15/03/2024"

// Wrap matches in tags
text.replace(/\b\w{5,}\b/g, '<strong>$&</strong>')

Frequently asked questions

How do I replace all matches with a regex?

Enable the g (global) flag. Without g, String.replace() only replaces the first match. With g all occurrences are replaced. The tool applies g by default in Replace mode.

What is $& in a replacement string?

$& refers to the entire matched substring. For example, text.replace(/\w+/g, '[$&]') wraps every word in brackets.

How do case-insensitive replacements work?

Enable the i flag. The pattern will match regardless of case, but the replacement string is literal — the case of the original match is not preserved. To preserve case you need a function replacement in code.

Can I use multiline replace?

Enable the m flag to make ^ and $ match the start and end of each line. Combined with g, you can replace patterns at the start or end of every line in a multi-line string.

Related tools