Find and Replace Text
Find and Replace Text online.
Find & Replace Text Tool — Complete Guide (2025)
Quickly search and replace text inside documents, code, or large blocks of content. This guide explains all options — basic find, replace all, case sensitivity, whole-word matching, and advanced regular expressions — and includes a ready-to-use HTML + JavaScript example you can copy and run in your browser.
What is a Find & Replace Tool?
A Find & Replace tool searches a body of text for specific terms or patterns and replaces them with new text. It’s an essential feature in editors and productivity tools — useful for correcting typos, refactoring code (renaming functions or variables), standardizing formatting, or updating dates and links in bulk.
Why Use Find & Replace?
- Save time: Make hundreds of edits in seconds instead of manually editing each instance.
- Improve accuracy: Reduce human error when updating repeated terms or values.
- Refactor code safely: Rename identifiers consistently across a project.
- Data cleanup: Normalize whitespace, remove unwanted characters, or fix formatting.
Common Features & Options
| Feature | What it does |
|---|---|
| Find | Locate exact words, phrases, or patterns. |
| Replace | Substitute matched text with new text. |
| Replace All | Replace every match in the document in one operation. |
| Case Sensitive | Match text only when the case (upper/lower) is identical. |
| Whole Word | Match only whole words (not substrings). |
| Regular Expressions (Regex) | Use patterns to match complex text structures (dates, emails, repeated groups). |
| Preview | Show a preview of replacements before applying changes. |
| Undo | Revert changes if the replacement had unexpected effects. |
How to Use — Step-by-Step
- Paste or open your text in the editor area.
- Enter the text (or regex) you want to find.
- Enter the replacement text.
- Choose options: case sensitive, whole word, or regex.
- Click
Previewto review all matches and replacements. - If everything looks correct, click
ReplaceorReplace All. - Use
Undoif any change needs reverting.
Practical Examples
1. Fix a repeated typo
Find: teh — Replace with: the
2. Update an old domain
Find: http://oldsite.com — Replace with: https://newsite.com
3. Rename a variable in code (whole-word)
Find: count, Replace with: totalCount, enable Whole Word to avoid changing counter or discount.
4. Use regex to reformat dates (MM/DD/YYYY → YYYY-MM-DD)
Find (regex): (\d{1,2})/(\d{1,2})/(\d{4})
Replace: $3-$1-$2 — then normalize single-digit months/days if needed.
Copy & Run: Simple Find & Replace HTML + JavaScript
This is a lightweight client-side tool you can copy into an HTML file and open in your browser. It supports case sensitivity, whole-word matching, regex, preview, and replace all.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Find & Replace Demo</title>
<style>body{font-family:Arial;margin:20px;}textarea{width:100%;height:160px;padding:8px}</style>
</head>
<body>
<h2>Find & Replace Demo</h2>
<label>Text to edit:</label>
<textarea id="source">Type or paste text here... Example: call count(); and discount variable.</textarea>
<div style="display:flex;gap:8px;margin-top:10px;">
<div style="flex:1">
<label>Find:</label>
<input id="find" type="text" placeholder="Enter text or regex">
</div>
<div style="flex:1">
<label>Replace with:</label>
<input id="replace" type="text" placeholder="Replacement text">
</div>
</div>
<div style="margin-top:8px;">
<label><input type="checkbox" id="caseSensitive"> Case sensitive</label>
<label style="margin-left:10px;"><input type="checkbox" id="wholeWord"> Whole word only</label>
<label style="margin-left:10px;"><input type="checkbox" id="useRegex"> Use regex</label>
</div>
<div style="margin-top:10px;">
<button onclick="previewReplace()">Preview Matches</button>
<button onclick="applyReplace()">Replace All</button>
<button onclick="undoReplace()">Undo</button>
</div>
<h3>Preview / Result:</h3>
<pre id="result" style="background:#f6f8fb;padding:10px;border:1px solid #e3eefc;height:200px;overflow:auto;"></pre>
<script>
let lastText = '';
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
function getRegex(findVal, caseSensitive, wholeWord, useRegex) {
if (!useRegex) {
findVal = escapeRegExp(findVal);
}
if (wholeWord) {
findVal = '\\b' + findVal + '\\b';
}
let flags = caseSensitive ? 'g' : 'gi';
try {
return new RegExp(findVal, flags);
} catch (e) {
alert('Invalid regular expression: ' + e.message);
return null;
}
}
function previewReplace() {
const src = document.getElementById('source').value;
const findVal = document.getElementById('find').value;
const replaceVal = document.getElementById('replace').value;
const caseSensitive = document.getElementById('caseSensitive').checked;
const wholeWord = document.getElementById('wholeWord').checked;
const useRegex = document.getElementById('useRegex').checked;
if (!findVal) {
document.getElementById('result').textContent = 'Please enter text to find.';
return;
}
const regex = getRegex(findVal, caseSensitive, wholeWord, useRegex);
if (!regex) return;
// Show matches highlighted in preview
const preview = src.replace(regex, match => '[MATCH:' + match + ']');
document.getElementById('result').textContent = preview + '\\n\\n-- Replaced Preview --\\n' + src.replace(regex, replaceVal);
}
function applyReplace() {
lastText = document.getElementById('source').value; // save for undo
const findVal = document.getElementById('find').value;
const replaceVal = document.getElementById('replace').value;
const caseSensitive = document.getElementById('caseSensitive').checked;
const wholeWord = document.getElementById('wholeWord').checked;
const useRegex = document.getElementById('useRegex').checked;
if (!findVal) { alert('Please enter text to find.'); return; }
const regex = getRegex(findVal, caseSensitive, wholeWord, useRegex);
if (!regex) return;
const newText = document.getElementById('source').value.replace(regex, replaceVal);
document.getElementById('source').value = newText;
document.getElementById('result').textContent = 'Replacement applied. Use Undo to revert.';
}
function undoReplace() {
if (lastText === '') { alert('No action to undo.'); return; }
document.getElementById('source').value = lastText;
document.getElementById('result').textContent = 'Undo completed.';
lastText = '';
}
</script>
</body>
</html>
This demo performs everything locally in your browser — no uploads, no servers.
Best Practices & Safety Tips
- Preview first: Always preview replacements before applying them — especially when using regex.
- Use whole-word matching: When renaming identifiers, enable Whole Word to avoid partial replacements.
- Test on a copy: Work on a copy of your document or repository when running broad replacements.
- Version control: Commit changes to version control (Git) before bulk replacements so you can revert if needed.
- Be careful with regex flags: The global
gflag and case-insensitiveiflag change behavior — know what they do. - Backups: Keep backups of important files before running script-based replacements.
Advanced Use Cases
Find & Replace is more than a text editor feature — it powers many tasks:
- Data migration: Update CSV headers, change date formats, or normalize separators.
- Codebase refactor: Rename classes, methods, or variables across many files (use IDE-aware tools for safety).
- Templating: Replace placeholders like
{{NAME}}with real values in bulk. - Log sanitization: Remove PII or redact tokens using regex before sharing logs.
Regex Quick Reference for Find & Replace
| Pattern | Meaning / Example |
|---|---|
^ | Start of line |
$ | End of line |
\d | Digit (0–9) |
\w | Word character (letters, digits, underscore) |
\s | Whitespace (space, tab, newline) |
.+ | One or more of any character (except newline) |
(...) | Capture group — use $1, $2 in replacement |
\b | Word boundary (useful for whole-word matching) |
FAQs
Q: Will the demo handle very large files?
A: Client-side JavaScript can handle moderately large text, but for multi-megabyte files or many files, use a specialized desktop app or server-side script.
Q: Is regex required?
A: No. Basic find & replace works without regex. Use regex only when you need pattern matching or capture groups.
Q: Can I undo a Replace All?
A: The simple demo supports a single-step undo. For complex workflows, use version control or save a backup before replacing.
Q: Are my documents uploaded?
A: The provided demo runs entirely in your browser. Nothing is sent to a server unless you run a tool that explicitly uploads files.