Regex Find and Replace
About this tool
About Regex Replace
Rewrite text with a pattern instead of by hand. Type a JavaScript regular expression, a replacement and your text, and the Result tab shows the rewritten text immediately, while the highlights on the left show exactly which parts will change. Reorder pieces with capture groups, for example turning 2024-03-15 into 15/03/2024 with the replacement $3/$2/$1, or use named groups and $<day>/$<month>/$<year> for something readable months later. $& inserts the whole match, $` and $' the text before and after it, and $$ a literal dollar sign. Turn the global flag off to replace only the first match, and the status line tells you how many replacements were made. Copy the result straight from the panel. Invalid patterns get a plain explanation, and a pattern that backtracks for too long is stopped instead of freezing the tab. Everything happens in your browser, so the text you edit is never uploaded.
Built and maintained by Abhi JainUpdated
How to Find and Replace with Regex
- 1
Write the pattern
Enter the regex in Regular expression and keep the global flag on to replace every match.
- 2
Write the replacement
Type into Replace with, using $1, $<name> or $& to reuse matched text.
- 3
Paste your text
Paste into Test string; the Result tab shows the rewritten text as you type.
- 4
Copy the result
Click Copy on the Result tab, or switch to Matches to check each match.
Regex Replace: questions and answers
How do I use a capture group in a regex replacement?
Wrap part of the pattern in brackets and refer to it as $1, $2 and so on in the replacement. For example, the pattern (\w+)\s(\w+) with the replacement $2 $1 swaps two words.
How do I replace all matches, not just the first?
Turn on the g (global) flag. Without it, JavaScript's replace changes only the first match. In code, you can also use replaceAll with a global regex.
How do I insert a literal dollar sign?
Write $$ in the replacement. A single $ followed by a digit, &, `, ' or <name> has a special meaning, so doubling it is the safe way to get one $.
Is the replacement the same as in JavaScript code?
Yes. The preview runs String.prototype.replace in your browser with the same pattern, flags and replacement string, so the result matches text.replace(/pattern/flags, replacement).
More Regex Tester presets
Related tools
- Regex LibraryReady-made, tested regex patterns for emails, URLs, IPs, dates, phone numbers, Indian PAN, GSTIN, PIN and more, with code for five languages.
- Regex Match ExtractorExtract every regex match or capture group from text into a clean list, JSON array or CSV, with presets, de-duplication and sorting.
- Regex EscapeEscape special characters so literal text is safe inside a regular expression, for JavaScript, Python, POSIX or a character class.
- Diff CheckerCompare two texts by line, word or character, side by side or unified, with ignore options, stats and a downloadable patch.
- JSON FormatterBeautify, minify and validate JSON with exact error locations, without changing a single value.