Skip to main content

Find and Replace Text with Optional Regex

Find text matches and replace them using literal text or an optional regular expression. Review match counts before applying the result.

Find and Replace workspace

Recipes
Found 0 matches — enter a pattern to begin
Input
Output
Hello there! Contact us at [email protected], [email protected], or [email protected].

We will reply within 24 hours.   Multiple   spaces   need fixing.

#feedback #toolk #2026 🚀

Literal or Regex

Toggle between plain-text find (with whole-word and case-insensitive options) and full ECMAScript regex with capture-group backreferences ($1, $2 in the replacement).

Backreferences Work

In regex mode, capture groups in the find pattern (parentheses) can be referenced as $1, $2 in the replacement — swap columns, restructure dates, normalize casing.

Live Match Count

See exactly how many matches will be replaced before confirming. Recipe presets demonstrate common patterns (strip emoji, mask emails, collapse spaces).

100% Client-Side

All find-and-replace runs in your browser via native String.replace. Text never leaves the page — safe for logs, configs, or any sensitive content.

Find and Replace Text in Bulk — Plain or Regex

Find text matches and replace them using literal text or an optional regular expression. Review match counts before applying the result. A broad pattern can replace more than you intended. Test a small sample and inspect surrounding text before applying a replacement to a long document. Regex capture groups and replacement tokens follow JavaScript rules; literal replacements may be safer for ordinary wording changes.

How to use find and replace on your text

  1. Paste or type your text into the input pane on the left.
  2. Type the Find term, then the Replace string. The output and match count update as you type.
  3. For plain swaps, leave regex off and use the Case-insensitive and Whole word toggles as needed.
  4. For patterns, turn on Regex — add parentheses to capture groups and reference them as $1, $2 in the replacement. Enable Multiline to anchor ^ and $ to each line.
  5. Copy the result, or click Apply replacement to input to chain another find-and-replace on the output.

How find and replace works

Find and replace performs a search-and-substitute over text. In literal modeyour find term is matched character-for-character; in regex mode it is compiled into a JavaScript RegExp and matched as a pattern. This tool always uses the global flag (g), so every occurrence is replaced, not just the first. The replacement string supports special tokens defined by the ECMAScript String.prototype.replace spec: $1$99 for capture groups, $& for the whole match, and $$ for a literal dollar sign.

The case-insensitive toggle adds the i flag, so Apple, APPLE, and apple all match. The whole-word toggle (literal mode only) wraps your term in \b word boundaries so cat matches the word but not category. The multiline toggle adds the m flag, which changes ^ and $ from matching the start and end of the whole input to matching the start and end of every line.

Worked examples: find → replace

Literal · whole word on

find: cat → replace: dog — "the cat in category" becomes "the dog in category"

Regex · capture groups

find: (\d{4})-(\d{2})-(\d{2}) → replace: $3/$2/$1 — 2026-05-11 becomes 11/05/2026

Regex · multiline on

find: ^\s+ → replace: (empty) — strips leading whitespace from every line

Edge case · literal $ in the replacement

Want to replace USD with $1.00? In literal mode that $1 would normally be read as a capture-group backreference and vanish. This tool auto-escapes every $in a literal replacement to $$, so $1.00 comes out exactly as typed. Switch to regex mode only when you actually want $1 to mean a capture group.

Syntax Reference

FeatureSyntax / ToggleNotes
Plain text (literal mode)find: cat → replace: dogReplaces every occurrence of the literal string. Use whole-word toggle to avoid partial matches.
Case-insensitive+ Aa toggleAdds the "i" flag — "Apple", "APPLE", "apple" all match the same pattern.
Whole word only+ "Wb" toggle (non-regex mode)Wraps the literal pattern in \b boundaries; matches "cat" but not "category".
Regex character classfind: [aeiou] → replace: *Replaces every vowel with an asterisk. Square brackets define a set.
Regex backreferencefind: (\w+) (\w+) → replace: $2 $1Captures two words with parentheses, swaps them. $1, $2 reference the captures.
Regex anchorsfind: ^foo → replace: bar (multiline)"^" matches line start when multiline mode is on; otherwise only the very start.
Regex quantifiersfind: \d{3,5}Matches 3 to 5 digits. {n,m} = at least n, at most m occurrences.

Five Practical Find-and-Replace Recipes

1. Anonymize Email Lists

find: \b[A-Za-z0-9._%+-]+@\S+\b → replace: [email]

Replace every email with [email] before sharing logs externally. Regex mode on.

2. Collapse Duplicate Spaces

find: " +" → replace: " "

Normalize whitespace from scraped or copy-pasted content. Regex mode on.

3. Reorder Date Formats

find: (\d{4})-(\d{2})-(\d{2}) → replace: $3/$2/$1

Convert ISO 8601 dates to US format using capture-group backreferences.

4. Strip Trailing Whitespace

find: \s+$ → replace: (empty) · multiline on

Clean trailing whitespace from every line of pasted source code.

Four Pitfalls to Watch For

1. Greedy Quantifiers Match Too Much

In regex, .* is greedy — it matches as much as possible. For HTML-like content, use .*? (non-greedy) instead. Otherwise <b>hello</b> world <b>again</b> collapses across both tags.

2. Special Characters Need Escaping

In regex mode, . matches any character. To match a literal period, write \. — same for ( ) [ ] * + ? | ^ $ \\. Literal mode handles this automatically.

3. Substring vs Word Match

Searching "cat" matches inside "category", "scattered", "duplicate". Turn on Whole Word (literal mode) or add \b boundaries (regex mode) when you want word-only matches.

4. Replace With $1 Without Capture

$1 in the replacement is meaningless if your find pattern has no parentheses. The output will contain literal "$1" characters. Add ( ) around the part of the pattern you want to capture.

The literal-mode trap most find-and-replace tools fall into

JavaScript's native String.replace treats $1, $&, and $$ as special replacement tokens even when the find term is a plain string. So a naive literal find-and-replace that swaps price for $1 each silently drops the $1, because there is no capture group to back-reference. This tool escapes every $ in a literal replacement to $$ before substituting, so dollar signs always survive. In regex mode the tokens are honored, giving you full backreference power.

Two more concrete limits: the match preview lists up to 200 matches with their line and column, and the engine guards against zero-width matches (an empty regex match advances the cursor by one so the loop never hangs). Every replace uses the global flag, so the live count is the exact number of substitutions that will happen.

Last updated: September 15, 2026 · Runs 100% in your browser — no uploads, tool input is not sent to Toolk.

Frequently asked questions

Is my text uploaded to a server when I run a replacement?

Never. Matching and substitution happen through native String.prototype.replace in your browser tab, and Toolk’s page analytics do not receive the input or the output. Run any replacement with DevTools open and the Network tab stays silent — which is what makes the tool safe for log files and config snippets that contain secrets.

Does it replace every match or only the first occurrence?

Every occurrence, in one pass. The pattern always carries JavaScript’s global flag, so nothing is left behind, and the live match counter shows exactly how many substitutions will land before you apply anything.

What happens to dollar signs like $1 in literal mode?

They survive verbatim. JavaScript would normally read $1 as a capture-group backreference even for plain-string searches, so this tool escapes every $ to $$ before substituting in literal mode. Replacing price with $1.00 really outputs $1.00; switch to regex mode only when you want backreferences.

Why did my regex match more text than I expected?

Greedy quantifiers are the usual culprit: .* consumes as much as possible, so two separate tags collapse into one match. Use the non-greedy .*? form, anchor patterns with \b word boundaries, and watch the live match count — an over-eager pattern shows up immediately as a suspiciously large number.

Any workflow tip for building a tricky pattern?

Prototype it in Toolk’s Regex Tester (/tools/regex-tester), then paste the finished pattern here to run it across the whole document. Chain steps with Apply replacement to input — strip emoji first, then collapse duplicate spaces — instead of betting on one fragile mega-pattern.

Need a different tool?

Browse all 103 browser-based tools (103 currently marked free), or tell us what useful utility we should build next.

Browse all tools