Find and Replace Text
Replace text or regex matches across large documents with case options.
About the Find and Replace Text
The Find and Replace tool searches your text for a pattern and substitutes every match with replacement text. It supports plain-text matching, case-insensitive matching, whole-word matching, and full regular expression mode for complex patterns. The tool reports exactly how many replacements were made, so you can verify that the operation did what you expected before committing to the result.
Find and replace is one of the most common text editing operations, used for everything from renaming variables in code to updating product names in documentation to swapping outdated terminology across a large corpus. Doing it manually is error-prone — you miss occurrences, introduce typos, and lose track of what you have already changed. A tool-based replacement is consistent, thorough, and auditable.
The regex mode unlocks powerful pattern-based replacements. You can capture groups and reference them in the replacement, match word boundaries, use character classes, and apply lookahead assertions. This makes it possible to perform transformations that would be impossible with plain text matching — like extracting domain names from URLs, reformatting dates, or normalizing phone numbers.
How It Works
In plain-text mode, the search string is first escaped for regex special characters (so a literal . in your search does not match any character). If whole-word mode is on, \b word boundaries are added around the pattern. If case-insensitive mode is on, the i flag is added. The resulting RegExp object is used with String.replace(), and a counter function tallies each match.
In regex mode, the search string is used directly as a regular expression pattern. This means special characters like ., *, +, ?, [, (, {, ^, $, |, and \ have their regex meanings. You can use capture groups (parentheses) and reference them in the replacement string using $1, $2, and so on. See our regex cheat sheet for a quick syntax reference.
The global flag (g) is always set so all matches are replaced, not just the first. Without g, JavaScript's replace() would only replace the first occurrence — a common gotcha when migrating from other languages. The counter function receives each match and returns the replacement string, incrementing a counter on each call.
Worked Examples
With the default input “The cat sat on the mat. The cat was fat. The cat wore a hat.” and find=“cat”, replace=“dog”, you get 3 replacements: “The dog sat on the mat. The dog was fat. The dog wore a hat.” Note that “cat” inside “category” would also be replaced in plain mode — enable whole-word mode to prevent that.
Try a regex replacement: find \b(\w+)@(\w+)\.com\b, replace $2@$1.com. This swaps the local and domain parts of email addresses: “user@example.com” becomes “example@user.com”. The capture groups $1 and $2 reference the matched username and domain.
For case-insensitive find on “cat”, enable the case-insensitive option. Now “Cat,” “CAT,” and “cat” all match. The replacement text is always inserted verbatim — it does not inherit the case of the matched text.
When to Use This Tool
- Bulk-renaming variables or functions across a codebase migration.
- Updating product names or brand terminology across documentation.
- Reformatting dates from MM/DD/YYYY to YYYY-MM-DD using regex capture groups.
- Normalizing phone numbers to a consistent format.
- Removing tracking parameters from a list of URLs.
- Extracting and reformatting structured data from free-text logs.
- Cleaning up copy-pasted content that has smart quotes or non-breaking spaces.
Limitations & Disclaimer
This tool performs single-pass replacement — it does not support multi-step or conditional replacement logic. Regex mode uses JavaScript's regex engine (ECMAScript specification), which does not support lookbehind assertions in older browsers (Safari before 16.4) or named capture groups in older engines. Very long inputs (millions of characters) may cause performance issues. The tool does not support multi-line regex by default; add the m flag manually in regex mode if needed. See our disclaimer for full terms.
Frequently Asked Questions
How do I use capture groups in the replacement?
In regex mode, parentheses create capture groups. Reference them in the replacement string using $1, $2, and so on. For example, find (\d{4})-(\d{2})-(\d{2}), replace $3/$2/$1 turns "2024-03-15" into "15/03/2024".
What special characters do I need to escape in plain mode?
None. In plain-text mode, all regex special characters are automatically escaped. A search for "price: $9.99" matches the literal text, not a regex pattern. Only enable regex mode if you want to use pattern syntax.
Why does whole-word mode not work with regex?
Whole-word mode adds \b word boundaries around the pattern, which is itself a regex feature. If you are already writing regex, you should add \b yourself. The tool flags this as an error to avoid confusing behavior.
What is the difference between this and my text editor's find/replace?
Functionally, very similar. This tool runs in the browser, handles large inputs without file-size limits, and provides a clear count of replacements. It is useful when you want to paste a large block of text, make replacements, and copy the result without opening a file in an editor.
Can I replace newlines or tabs?
In regex mode, yes. Use \n for newlines, \t for tabs, and \r for carriage returns. In plain mode, you cannot search for these characters directly - switch to regex mode.
Is my text uploaded anywhere?
No. All replacement happens in your browser using JavaScript's native String.replace(). Your text never leaves your device.
Last updated: September 9, 2026 · Author: HT99 Tools Editorial Team