Skip to content

Find & Replace

Run find-and-replace across a whole document with optional case sensitivity, whole-word boundaries, and full JavaScript regular expressions, including capture groups referenced as $1 to $9 in the replacement. With regex off your search is matched literally; every match is counted and highlighted before you commit, an invalid pattern is reported inline and leaves your text untouched, and everything runs in your browser.

How Find & Replace works

  1. Paste your text and type what you are looking for.

  2. Turn on regex if you need patterns or capture groups such as $1.

  3. Check the highlighted matches and the match count.

  4. Apply the replacement, then copy the result.

When to use Find & Replace

  • Renaming a term across an entire document at once — a client name, a product, a heading style — with a live count of every occurrence before you commit.
  • Standardising spelling in a draft, such as swapping every “color” for “colour” or every straight apostrophe for a curly one.
  • Reordering structured text with a capture group, for example turning a column of “Surname, Firstname” entries into “Firstname Surname”.
  • Collapsing whitespace or stripping stray markup left behind after a paste, using a regex like a run of spaces or a bracketed tag.
  • Fixing only whole-word matches so replacing “cat” does not also rewrite “category” or “scatter”.
  • Flattening text pasted from a PDF by matching newlines with regex and replacing them with a single space.
  • Making a single, first-only replacement — turning off “replace all” to change the opening instance and leave the rest untouched.
  • Chaining several edits in sequence, since the document is rewritten in place and stays ready for the next find.

Examples

Whole-word replace leaves neighbours alone

Input

Find “cat” with whole word on, replace with “dog”, across “The cat sat by the category shelf.”

Output

“The dog sat by the category shelf.”

Whole-word wraps the search as \b(?:cat)\b, so the “cat” inside “category” is not a match.

Regex capture group reorders a name

Input

Find “(\w+), (\w+)” with regex on, replace with “$2 $1”, across “Lovelace, Ada”

Output

“Ada Lovelace”

In regex mode the replacement field reads $1 through $9 as the groups captured by the pattern.

Literal mode treats special characters as themselves

Input

Find “a.m.” with regex off, replace with “AM”, across “Doors at 9 a.m. and 11 a.m.”

Output

“Doors at 9 AM and 11 AM.”

With regex off the search is escaped first, so each dot matches a real dot rather than any character.

First-only replacement

Input

Find “TODO”, replace with “DONE”, with “replace all” off, across “TODO wire up · TODO ship”

Output

“DONE wire up · TODO ship”

Only the first match changes; the highlighted preview still shows every match so you can see what is left.

How Find & Replace works under the hood

With regular expressions off, your search text is passed through an escape step that puts a backslash in front of every character with special meaning — the dot, asterisk, question mark, brackets, parentheses, and so on — before it becomes a pattern. That is what makes literal mode literal: typing “a.m.” looks for that exact string rather than treating each dot as “any character”. Turn regex on and your input is used as the pattern verbatim, giving you the full JavaScript syntax.

Whole-word matching wraps whatever survives the escape or regex step in word boundaries, as \b(?:your-search)\b. A boundary sits between a word character and a non-word character, so the search only fires when it is flanked by spaces, punctuation, or the ends of the text. Whole-word combines with the other switches: it can wrap a literal string or a regex, and it respects case sensitivity.

Matching runs with a global flag so every occurrence is found, plus the case-insensitive flag unless you turn case sensitivity on, plus the Unicode flag for correct handling of accented and non-Latin text. Some older patterns that Unicode mode rejects — a lone escape sequence, for instance — would otherwise fail outright, so the tool retries the same pattern without the Unicode flag before reporting an error. Such patterns still work, just without strict Unicode semantics.

Capture-group references in the replacement are applied per match. The tool locates each match across the whole document, then for the replacement it runs a single-match version of your pattern over just that matched slice, which is how $1 through $9 line up with the groups from the right occurrence rather than drifting. With “replace all” on, every match is rewritten; with it off, only the first is touched and the remainder are left exactly as they were.

An invalid regular expression never mangles or clears your text. The pattern is compiled inside a guarded step; if it throws, the error message is surfaced inline, the Apply button is disabled, and the document is returned unchanged. The moment the pattern compiles cleanly again, matching and highlighting resume. A runaway pattern that would match forever — a zero-width match such as a bare boundary or a star — is protected by advancing past empty matches and by a hard cap on the number of matches collected in one pass.

Common mistakes

  • Leaving regex on when you mean a literal replacement. With regex on, a search like “price ($)” treats the parenthesis and dollar sign as syntax, so it matches nothing or the wrong thing. Turn regex off and those characters are searched for exactly.
  • Expecting whole-word matching to fire inside a compound. “Whole word only” requires a boundary on each side, so it will not match the “sun” in “sunflower” or the “test” in “tested”. Turn it off when you want matches inside longer words.
  • Forgetting that a replacement with “replace all” off changes only the first match. If a later occurrence still shows the old text, check that switch before assuming the pattern is wrong — the highlighted preview confirms how many matches were found.
  • Writing a $1 reference without a matching capture group. In the replacement, $1 only resolves if the pattern actually has a first group in parentheses; with no group it is inserted as the literal text “$1”. Wrap the part you want to reuse in parentheses first.
  • Trying to match a line break by typing a real newline into the find field. Turn regex on and search for the newline escape, or for a run of whitespace, to flatten multi-line text — a plain Enter in the field will not do it.

Frequently asked questions

All tools

Search NeatKit

Jump to a tool, a page, or change the theme.