Regex Find & Replace

Find and replace text using regular expressions with live preview, capture group references, and common presets. All processing happens in your browser — nothing is sent to a server.

/ /
 
$1 $2 $3 $& $` $' \\n \\t
0 matches
Enter a pattern and source text to see live preview...
Before
After
  • No replacements yet. Run a replacement to see history.

Replacement String Reference

TokenDescriptionExample
$1, $2, ...Captured group by numberPattern (\w+)-(\w+), replace $2_$1
$&Entire matched substringWrap match: [$&]
$`Text before the matchDuplicate prefix
$'Text after the matchDuplicate suffix
$$Literal dollar signPrice: $$$1

Regex Quick Reference

TokenDescription
.Any character except newline
\dDigit [0-9]
\wWord character [a-zA-Z0-9_]
\sWhitespace
*0 or more
+1 or more
?0 or 1 (also: non-greedy modifier)
{n,m}Between n and m times
^ / $Start / end of string (or line with m flag)
(abc)Capture group
(?:abc)Non-capturing group
[abc]Character class
a|bAlternation (a or b)
(?=abc)Positive lookahead
(?<=abc)Positive lookbehind
Embed this tool on your site
<iframe src="https://devtoolbox.dedyn.io/tools/regex-replace" width="100%" height="700" frameborder="0" title="Regex Find & Replace"></iframe>

Frequently Asked Questions

How do capture group references like $1 and $2 work in regex replacement?
Capture groups are portions of a regex pattern enclosed in parentheses. In the replacement string, $1 refers to the first capture group, $2 to the second, and so on. For example, the pattern (\w+)@(\w+) with replacement '$2-$1' would transform 'user@domain' into 'domain-user'. You can also use $& for the entire match, $` for text before the match, and $' for text after the match.
What is the difference between the g, i, m, s, and u regex flags?
The 'g' (global) flag finds all matches instead of stopping at the first. The 'i' (case-insensitive) flag ignores letter casing. The 'm' (multiline) flag makes ^ and $ match line beginnings/ends. The 's' (dotAll) flag makes the dot (.) match newline characters too. The 'u' (unicode) flag enables full Unicode matching, allowing patterns like \p{Letter} to match characters from any language.
Can I use regex find and replace to convert date formats?
Yes. For example, to convert dates from MM/DD/YYYY to YYYY-MM-DD, use the pattern (\d{2})/(\d{2})/(\d{4}) with the replacement $3-$1-$2. This captures the month, day, and year as separate groups, then rearranges them in the replacement. The preset "Convert Date Formats" in this tool does exactly that.
Keyboard Shortcuts
Ctrl+Enter Replace All
Ctrl+Shift+C Copy result
Ctrl+L Clear all