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 →| Pattern | Replaced by |
|---|---|
$& | The full matched substring |
$1, $2… | Numbered capture group (1-indexed) |
$<name> | Named capture group |
$` | Text before the match |
$' | Text after the match |
$$ | Literal dollar sign |
Common examples:
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.
$& refers to the entire matched substring. For example, text.replace(/\w+/g, '[$&]') wraps every word in brackets.
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.
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.