Find and replace text

Replace every match in one pass, literally or with a JavaScript regular expression

The tool loads here. It needs JavaScript, because the work happens on your device.

Your files and your privacy

The search, the replacement and the text they are applied to all stay in this browser tab. Nothing is uploaded and nothing is autosaved, so a configuration file or a block of source code pasted here leaves no copy once you reload the page or select Clear data.

What this tool does

Search a block of text and replace all matches at once, with optional regular expressions, case sensitivity and whole-word matching. An invalid pattern is reported as a message and your text is left untouched.

It finds every occurrence of a search term, replaces them all in a single pass, and reports how many replacements it made. Three switches change how the term is read: Regex treats it as a regular expression rather than literal characters, Case sensitive is on by default and can be turned off, and Whole word requires a word boundary at each end so a search for cat leaves concatenate alone. A pattern that will not compile produces an error message and no change at all, which matters because a half-typed pattern is a normal step towards a working one.

How to use it

  1. Paste your text into the box, then type the search term and the replacement into the two fields.
  2. Leave Regex off to match the term literally; every special character in it is escaped, so a full stop matches a full stop and nothing else.
  3. Turn Regex on when you need a pattern, and use $1, $2 and so on in the replacement to reference its capture groups.
  4. Select Replace all and read the count reported afterwards. If it is not what you expected, select Undo and refine the pattern.

Example use cases

Supported input and output

Accepts

Produces

What this tool will not do

Common mistakes

Technical notes

In literal mode every regular-expression metacharacter in the search term is escaped before compilation, so it can only match itself; in regex mode the term is passed through as written. Whole word wraps whichever you get in \b(?:…)\b, as a non-capturing group, so an alternation such as cat|dog is bounded as a whole rather than binding the boundary to its first branch. Compilation happens inside a guard that returns an error value instead of throwing, and the engine’s own message is passed through without being double-prefixed. The count is taken by matching before replacing, then the standard string replacement runs — which is why the replacement honours $1 to $9, $& and $$ in both modes: only the search side is escaped.

Frequently asked questions

Which regular expression flavour does it use?
JavaScript’s own, compiled by the engine in the browser you are using. Patterns written for other flavours — PCRE, Python, or POSIX classes such as [:alpha:] — will either fail to compile or match something different.
Do capture groups work in the replacement?
Yes, in regex mode. Find (\d{4})-(\d{2})-(\d{2}) and replace with $3/$2/$1 to rewrite 2024-01-02 as 02/01/2024. A number beyond the groups in your pattern is left as literal text.
What happens if my regular expression is invalid?
You get the engine’s message explaining what was wrong, such as an unterminated group, and your text is left exactly as it was. Nothing is thrown, nothing is cleared, and you can keep editing the pattern.