# Find and Replace Text

URL: https://hifreetools.com/text/find-and-replace-text

> Paste any text, type what to find and what to replace it with, and get the rewritten result instantly — with case-insensitive, whole-word, and regular-expression modes and a count of how many replacements were made.

## Quick answer

To find and replace text, paste your content, enter the search term and the replacement, then choose options like case-insensitive, whole-word, or regex. The tool scans the text with the JavaScript string/RegExp engine in your browser, replaces every match globally, and shows the new text plus how many replacements were made.

## Formula

- Replacement rule: output = text with every match of find replaced by replace (global)
- Match flags: flags = "g" + (case-insensitive ? "i" : "") + (whole-word ? "u" : ""); whole-word wraps the pattern as (?<!W)(?:pattern)(?!W)

The tool turns your "find" term into a global regular expression and runs it over the text. In literal mode, special regex characters in your search term (such as . * ? ( ) [ ]) are escaped so they are matched as plain characters. In regex mode, your term is used as the pattern itself, so you can match digits with \d+, groups, alternation, and more, and reference captured groups like $1 in the replacement. The "case-insensitive" option adds the i flag so MATCH, Match, and match are all found. The "whole word only" option only accepts a match that is not touching a letter, combining mark, digit or underscore of any script (a Unicode-aware boundary, not JavaScript's ASCII-only \b), so "cat" no longer matches inside "category" and accented or non-Latin words work too. Matching is always global (the g flag), so every occurrence is replaced in one pass, and the tool reports the total number of replacements. All processing is synchronous and happens locally in your browser — nothing is uploaded.

## Examples

- Replace a word everywhere: Text: "The cat sat on the mat. The cat purred." — Find: cat, Replace: dog → The dog sat on the mat. The dog purred. (2 replacements)
- Case-insensitive match: Text: "Color colour COLOR" — Find: Color, Replace: X, with Case-insensitive on → X colour X (2 replacements)
- Whole word only: Text: "cat category catalog cat" — Find: cat, Replace: dog, with Whole word only on → dog category catalog dog (2 replacements)
- Regex to replace all numbers: Text: "Order 12, item 3, total 45" — Find: \d+, Replace: #, with Regular expression on → Order #, item #, total # (3 replacements)
- Delete characters: Text: "a,b,c,d" — Find: , (a comma), Replace: (empty) → abcd (3 replacements)

## FAQ

**Does it replace all matches or just the first one?**
All of them. The replacement always runs globally, so every occurrence of your search term is replaced in a single pass, and the tool shows you the total replacement count.

**How do I use regular expressions?**
Turn on the "Regular expression" option, then your search term is treated as a regex pattern. For example \d+ matches any run of digits and \s+ matches whitespace. In the replacement field you can reference captured groups with $1, $2, and so on.

**What does "whole word only" do?**
It only matches complete words: the match must not touch a letter, digit or underscore of any script, so accented and non-Latin words work too. Searching "cat" matches the standalone word "cat" but not the "cat" inside "category" or "scatter". In Chinese, Japanese or Thai a word only matches where spaces or punctuation set it off.

**How do I delete text instead of replacing it?**
Leave the "Replace with" field empty. Every match of your search term is then removed from the text. The replacement count tells you how many were deleted.

**Is my text sent to a server?**
No. The find-and-replace runs entirely in your browser using the built-in JavaScript engine, so your text never leaves your device and nothing is stored or uploaded.

**Why does my search term match unexpected characters?**
You are probably in regex mode, where symbols like . or * have special meaning (. matches any character). Turn regex off to match them as plain characters — literal mode escapes special characters, regex interprets them.

**Can I undo a replacement?**
The tool shows the result in a separate read-only box and never overwrites your original input, so you can adjust the find or replace fields and the output updates live. Your source text stays intact until you change it yourself.


## Sources

- [MDN: String.prototype.replace()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
- [MDN: Regular expressions guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions)

Runs in the browser; nothing is uploaded. Cite as: HIFreeTools, "Find and Replace Text", https://hifreetools.com/text/find-and-replace-text
