Find and Replace Text Online - Plain or Regular Expression, with Undo
Paste your text, type what to find and what to replace it with, and see the matches highlighted and counted as you type.
Maintained by Hirantha Sandaruwan Lakshan. Updated 13 October 2026.
About this tool
Choose plain text or a regular expression, match case or not, whole words only, and replace every match or just the first. Add more rules to run several find-and-replace pairs in order, and undo if the result is not what you wanted. Everything runs in your browser, so the text is never uploaded.
How it works
Plain mode matches your text exactly, letter for letter, and inserts the replacement as typed. A dollar sign in the replacement is just a dollar sign. Case matching is optional. Whole word only means the match must not touch a letter, a combining mark, a digit or an underscore on either side, which also works for Sinhala and Tamil words. Tick the escapes box if you want \n to mean a line break and \t a tab in the boxes.
Regular expression mode uses JavaScript syntax, and the replacement works exactly like String.prototype.replace. $1 to $99 insert numbered groups, $<name> inserts a named group, $& is the whole match, $` is the text before it, $' is the text after it and $$ is a dollar sign. A group number that does not exist stays as typed, and a group that took no part in the match gives an empty string. The table below shows each pattern with a worked result. The u flag is on by default so that \p{L} and emoji work. Turn it off if you need a pattern the u flag rejects, such as an escaped hyphen outside a character class.
Several rules run from the top, each on the result of the one before. The count table shows the matches and replacements for every rule, and the preview shows the first 20 matches of the rule you pick, each with its line number, the text around it and what it becomes. Use the result as the text makes the output the new input so you can carry on, and Undo steps back, up to 20 times.
Limits and safety. A regular expression can take a very long time on some texts, a problem known as catastrophic backtracking or ReDoS. JavaScript cannot interrupt a match that is already running, so the tool does three things. It limits the text to 2,097,152 characters (2 MB). It stops a rule after 100,000 matches, or after 1.5 seconds of searching (the clock is checked every 16 matches, so a single match that is already slow cannot be cut short), and replaces nothing. And before it runs a pattern it looks for the classic risky shapes, such as a repeated group that contains a repeat like (a+)+, alternatives that overlap like (a|aa)+, and a run of repeats that match the same characters like a*a*a*b, and waits for you to press Run anyway. That check is a heuristic. It cannot find every slow pattern, and it may hold back a pattern that is in fact fast.
Worked examples
Swap the parts of a date
Regular expression (\d{4})-(\d{2})-(\d{2}) with replacement $3/$2/$1 turns 2026-10-13 into 13/10/2026. The three groups are the year, the month and the day, and the replacement writes them in the order 3, 2, 1.
Use named groups
Regular expression (?<first>\w+) (?<last>\w+) with replacement $<last>, $<first> turns John Smith into Smith, John. A name is easier to read than a number once a pattern has more than two groups.
Squeeze extra spaces
The regular expression " {2,}" (a space followed by {2,}) matches two or more spaces in a row. With a single space as the replacement, "a b c" becomes "a b c".
Whole word only
Searching for cat with whole word on matches the two standalone cats in "cat concat cat" and leaves concat alone, so replacing with dog gives "dog concat dog". With whole word off the middle of concat is replaced too and the result is "dog condog dog".
Two rules in order
Rule 1 replaces colour with color and rule 2 replaces metre with meter. On "Our colour range, by the metre." the result is "Our color range, by the meter." and the count table shows one match for each rule.
Replacement patterns in regular expression mode, each tried on the text abc
| Pattern | Inserts | Find, then replace with, on abc | Result |
|---|---|---|---|
| $1 to $99 | The numbered group | (b) then <$1> | a<b>c |
| $<name> | The named group | (?<n>b) then <$<n>> | a<b>c |
| $& | The whole match | b then [$&] | a[b]c |
| $` | The text before the match | b then [$`] | a[a]c |
| $' | The text after the match | b then [$'] | a[c]c |
| $$ | A dollar sign | b then $$ | a$c |
| $2 with one group | Nothing: it stays as typed | (b) then $2 | a$2c |
Frequently asked questions
How do I replace text with a line break?
Tick the escapes box, then type \n in the Replace with box. In regular expression mode you can also type \n in the Find box to match line breaks. A single-line box cannot hold a real line break, which is why the escape is needed.
How do I use $1 and named groups in the replacement?
Switch to regular expression mode and put the part you want to reuse in brackets. $1 is the first bracket, $2 the second. For a named group write (?<year>\d{4}) and use $<year>. A group number that does not exist is left as typed, so a typing slip is easy to spot.
Why does it say my regular expression looks risky?
Some patterns, such as (a+)+$ or (a|aa)+$, can take exponentially longer as the text grows when the match fails. The tool recognises the common shapes and waits for you to confirm. If you press Run anyway on a pattern that really is slow, the tab can freeze until the match ends, so use a simpler pattern when you can.
What is the difference between whole word and \b in a regular expression?
In JavaScript \b only knows ASCII letters, digits and the underscore, so it fails for Sinhala, Tamil and accented words. With the u flag on, whole word mode checks for Unicode letters, marks and digits on both sides, so it works for those scripts. Turn the u flag off and it falls back to \b.
Can I undo a replacement?
Yes. The result is shown below the tool and your text is not changed until you press Use the result as the text. After that, Undo restores the text from before, and you can step back up to 20 times.
Why was nothing replaced when there were more than 100,000 matches?
To protect the page, a rule stops at 100,000 matches and replaces nothing, rather than showing a half-finished result. Make the search more specific, or split the text into parts and run them one at a time.
Is my text uploaded or stored?
No. The search and replace is done by JavaScript in your browser tab. Nothing is sent to a server and nothing is saved when you close the page.
Sources & references
Updated Oct 13, 2026