Skip to content

Find and Replace

Options

Result

Type a find pattern to begin

Estimates for educational purposes — not financial, medical, or legal advice. See terms.

Find and replace looks like a 5-second feature, until you’re trying to swap variable names in a project and something subtle breaks. Plain string replace, the kind every text editor offers, will happily change userId to accountId inside mainUserIdValidator — turning it into mainAccountIdValidator. The fix is almost always one of: whole-word matching, case sensitivity, or a regex.

This tool gives you all three options in one place, runs entirely in your browser, and shows you the match positions before you commit to the replacement. You see what’s about to change before it changes.

How it works

Internally, every search is normalized to a JavaScript regular expression. Plain text is escaped so metacharacters like . and * are treated literally. Whole-word wraps the pattern in \b...\b (word boundaries). Case-insensitive adds the i flag. Multiline adds m (only relevant in regex mode, for ^ and $).

Match positions are recorded with line and column numbers so you can scan them in the preview list. Replacement happens after all matches are collected, walking from the end of the input backwards so earlier match positions stay valid.

Regex replacement strings

In regex mode, the replacement supports the standard JavaScript substitution tokens:

  • $1, $2, … — the corresponding capture group
  • $& — the whole match
  • $$ — a literal $

For example, swapping the order of two words: find (\w+) (\w+) with replacement $2 $1 turns hello world into world hello.

In plain mode, all $ characters in the replacement are escaped — so you can paste $300,000 as a replacement without it trying to back-reference a non-existent group.

Example: renaming a variable safely

You want to rename userId to accountId in a 2000-line file. A naive plain replace would also catch mainUserIdValidator and userIds. Turn on whole word: only standalone occurrences match. Result: userId becomes accountId, but userIds (plural, no boundary after) and mainUserIdValidator (no boundary before) are left alone.

If you also need to catch userid and UserId, turn on case-insensitive. The whole-word constraint still applies.

Example: extracting and reformatting data

You have a list of Name <email@example.com> strings and want them as email@example.com (Name). Turn on regex mode. Find: (\w+) <([^>]+)>. Replace with: $2 ($1). Each line’s name and email are captured into groups 1 and 2, then reordered in the replacement.

Common mistakes

Plain mode $ confusion. If you type $1 as a plain replacement and expect a back-reference, you’ll get the literal text $1. Switch to regex mode for back-references; the plain-mode escape is intentional so you can replace text containing $ symbols.

Whole-word with non-word characters in the find pattern. \b is a zero-width assertion at a transition between word and non-word characters. If your find pattern starts or ends with a non-word character (a space, a slash, a punctuation mark), the whole-word option may not behave the way you expect — \b won’t fire next to those characters because they’re already non-word. Drop whole-word for those cases.

Multiline confusion. Multiline only changes what ^ and $ mean in regex mode — they become per-line anchors instead of input start/end. The . metacharacter is unaffected; it still doesn’t match newlines without the s (dotAll) flag, which this tool doesn’t expose. Use [\s\S] if you need a “any character including newline” pattern.

Catastrophic backtracking. A regex like (a+)+b against aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa! can take seconds to fail. The 5000-match cap saves you from runaway match counts, but it doesn’t save you from a single match that takes forever to fail. If the page seems to hang, tighten the pattern (e.g. a+b instead of (a+)+b).

What this tool does not do

It doesn’t preserve case during replacement (no smart-case substitution where FooBar and foobar happen in one pass). For that, you need separate runs.

It doesn’t work line-by-line; the entire input is treated as one string. Per-line transforms are better handled by the sort lines tool or by writing a regex anchored with multiline ^/$.

It doesn’t preview replacement diffs side-by-side — the result is shown in full, not as a diff against the source. For visual side-by-side comparison, use the text diff tool.

Frequently asked questions

What's the difference between plain mode and regex mode?

Plain mode treats your search text literally — a period matches a period, an asterisk matches an asterisk. Regex mode interprets the find field as a JavaScript regular expression, so '.', '*', '+', parentheses, and other metacharacters have their special meanings. Use plain mode for everyday substitutions; switch to regex when you need patterns or back-references.

Why doesn't my $1 backreference work in plain mode?

Plain mode escapes $ characters in the replacement so users can substitute literal dollar amounts without surprises. To use $1, $2, or $& back-references, turn on regex mode and use capture groups in the find pattern, like (\\w+) and replacement $1.

Why is the match count capped at 5000?

Pathological patterns (a regex matching every character of a long input) can produce hundreds of thousands of matches, which freezes the page during rendering. Capping at 5000 keeps the UI responsive. The 'capped' indicator appears when the limit was hit; if you genuinely need more, narrow the pattern, or run the replace and then re-run on the result to chip away in batches.

How does whole-word work with non-ASCII text?

Whole-word uses JavaScript's \\b word-boundary, which treats word characters as [A-Za-z0-9_] only. So 'café' followed by punctuation works, but accented characters inside the word may behave unexpectedly because é is not a word character to \\b. For non-ASCII whole-word matching, switch to regex mode and use Unicode property escapes (\\p{L} with the u flag).

Does the multiline option matter in plain text mode?

No — multiline only affects the meaning of ^ and $ in regex mode, where it makes them match per-line instead of input start/end. In plain mode (and in regex mode without ^ or $ in the pattern), the option has no effect, so the toggle is greyed out unless regex mode is on.