What is a regex replace tool?
A regex replace tool finds every piece of text that matches a regular expression and swaps it for something else. Type a pattern such as "fox" and a replacement such as "cat", and every fox in the text becomes a cat. The default text here has 2 matches for "fox", and the output has 13 words — the same as the input, because each replacement is one word for one word.
Regular expressions describe shapes, not just words. The pattern \d+ matches any run of digits, so one pattern can replace every number in a document. The pattern (\w+)@(\w+) matches email-like text and captures the two halves, so the replacement $2@$1 swaps them. That is the power of regex replace: one rule, applied everywhere at once.
This tool is different from the regex tester on this site, which only shows matches without changing anything. Use the tester to work out whether a pattern matches what you think it does, and this tool to apply the change to the whole text.
How regex replace works
The tool builds a JavaScript RegExp from your pattern and runs String.replace with the global flag, so every match in the text is replaced, not just the first. The default pattern "fox" matches twice in the default text — once in "brown fox jumps" and once in "The fox is quick" — so the match count is 2 and both become "cat".
Parentheses in the pattern capture groups, and the replacement can refer to them with $1, $2, and so on. The pattern (\w+)@(\w+) captures the part before the @ as group 1 and the part after it as group 2, so the replacement "$2@$1" swaps the two halves. A replacement of "$1" on its own keeps only the first group and drops the rest of the match.
The ignore-case box adds the i flag, so "fox" also matches "Fox" and "FOX". Without it, the match is case-sensitive, and "Fox" at the start of a sentence is left alone. The output updates live as you type, so you can see the effect of each change to the pattern at once.
Patterns and replacements, explained
A literal pattern matches itself: "fox" matches the word fox, and nothing else. A pattern with a character class matches a set: [0-9] matches any digit, [a-z] matches any lower-case letter, and \d is the shorthand for any digit. A pattern with a quantifier matches a run: \d+ matches one or more digits, so "42" matches as one match, not two.
Anchors limit where a match can sit. ^ matches the start of the text and $ matches the end, so "^The" matches "The" only at the very start. Without anchors, a pattern matches anywhere, which is usually what you want for a replace across a whole document.
The replacement is plain text except for $ sequences. $1 inserts the first captured group, $2 the second, $& inserts the whole match, and $$ inserts a literal dollar sign. A replacement of "$1" with a pattern of "(\w+)" would replace every word with itself — a useful test that the pattern matches what you think it does.
Backreferences are the part of a replacement that makes it powerful, because they let the replacement reuse what the pattern found. A pattern with a group, such as (\w+)@(\w+), captures the two halves of an email address, and a replacement of $2@$1 swaps them. The dollar sign and the number are the reference, and the number is the position of the group in the pattern, counting from one. A replacement with no backreference is just a fixed string, and a replacement with one is a transformation that adapts to every match.
A worked example: renaming a word
Take the default text: "The quick brown fox jumps over the lazy dog. The fox is quick." It has 13 words. The pattern "fox" matches 2 times, and the replacement "cat" turns both into cats: "The quick brown cat jumps over the lazy dog. The cat is quick." The word count stays 13, and the character count stays 62, because cat and fox are both three letters.
Try a shape instead of a word. Change the pattern to \d+ and the text to "Order 42 and 7 shipped" and the replacement to "#", and both numbers become #: "Order # and # shipped". One pattern replaced every number in the text, which is the job regex exists for.
Try a group swap. Set the text to "ada@example.com", the pattern to "(\w+)@(\w+)", and the replacement to "$2@$1", and the output is "example@ada.com". The two halves swapped, which is a change no plain find-and-replace can do.
Who uses a regex replace tool, and why
Developers are the main users. Renaming a variable across a file, reformatting dates from 2024-01-15 to 15/01/2024, or stripping a prefix from a hundred lines are all one pattern and one replacement. Doing them by hand means editing every line; regex does them all at once.
Data workers are the second group. A column of phone numbers in mixed formats, a list of names with extra spaces, or a log file with timestamps to remove all need the same treatment: one pattern that describes the mess, and one replacement that fixes it.
Writers and editors are a third group. Replacing a character's name through a whole chapter, or normalising straight quotes to curly quotes, is a regex replace job. A regex tester is the place to check the pattern first, before applying it to the whole text.
Editors are a third group. A manuscript with a repeated formatting error — a double space after every full stop, a date written three different ways, a name spelt two ways — is fixed fastest with a pattern and a replacement, because the same fix applies to every occurrence at once. The replace tool is the fast part of that job; the slow part is writing a pattern that matches only the error and not the correct text next to it, and the tester is where that pattern is checked.
Regex replace vs regex tester
A tester shows matches; a replace tool changes them. The regex tester on this site highlights every match of a pattern in your text, which is how you check that the pattern matches what you think it does. This tool applies the replacement to those matches, which is the step after the check.
The safe workflow is tester first, replace second. Test the pattern on a small sample, read the highlighted matches, and fix the pattern until it matches exactly the text you want to change. Then paste the same pattern here with the replacement, and apply it to the whole document.
Both tools share the same JavaScript regular expression engine, so a pattern that matches in the tester matches here too. A case converter fixes the capitalisation of text before a pattern runs on it, so a pattern written for lower-case letters matches. A word counter counts the words before and after a replacement, which shows how much text a pattern actually changed.
A replace tool is not a tester, and the distinction matters when the pattern is new. A tester shows every match highlighted in the original text, which is the view that reveals a pattern matching too much or too little. A replace tool shows the result after the change, which hides the matches that were made and shows only the text that is left. Use the tester to check the pattern and the replace tool to apply it — the two views answer different questions, and the tester first is the order that avoids a bad replacement.
Common regex replace mistakes
The first mistake is a pattern that matches too much. The pattern ".*" matches everything, so replacing it with "x" deletes the whole text. Test the pattern on a small sample first, and read the match count — if it is far higher than you expected, the pattern is too broad.
Second: forgetting the global flag. This tool always replaces every match, but in code, a replace without the global flag changes only the first match. If a script replaces one fox and leaves the second, the missing flag is the cause.
Third: unescaped special characters. A pattern of "example.com" matches "exampleXcom" too, because the dot means any character. Escape it — "example\.com" — when you mean a literal dot. The same applies to $, ^, *, +, ?, (, ), [, ], {, }, and |.
Fourth: $ in the replacement. A replacement of "$1" with no groups in the pattern inserts nothing, because there is no group 1. And a replacement containing a literal dollar sign needs $$, or the dollar sign is read as the start of a group reference.
A second mistake is using a greedy quantifier where a lazy one was needed. A pattern such as <.*> on a line with two tags will match from the first angle bracket to the last one, swallowing both tags and everything between them, because the star takes as much as it can. The fix is a question mark after the quantifier — <.*?> — which makes it lazy, so it stops at the first closing bracket. The greedy match is correct by the rules of the engine, which is why it is so confusing: the pattern did exactly what it was told, and what it was told was wrong.
How to use this regex replace tool
Paste your text into the first box — the default has 2 matches for "fox" — then type the pattern and the replacement. The replaced text updates live in the box below, with the match count, the output character count, and the output word count above it.
To use captured groups, put parentheses in the pattern and $1, $2 in the replacement. To match regardless of case, tick the ignore-case box. To copy the result, use the Copy button next to the output box.
Everything runs in your browser. No sign-up, no account, no data sent anywhere — your text never leaves your device. It works offline once the page has loaded. Test the pattern on a small sample first, and read the match count before you trust the replacement on a long document.
Paste the text, type the pattern, and type the replacement, then press replace. The result shows the new text with the replacement count above it, and the count should match what you expected — if you expected five replacements and the count says one, the pattern is narrower than you thought. To check a pattern before replacing, run it in the tester first, which highlights every match without changing anything. When the count matches and the result reads right, copy the new text.