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
Paste your text into the box, then type the search term and the replacement into the two
fields.
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.
Turn Regex on when you need a pattern, and use $1, $2 and so on in the replacement to
reference its capture groups.
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
Swapping a renamed domain, product name or variable throughout a pasted file.
Reformatting a column of dates with a capture-group pattern, turning 2024-01-02 into
02/01/2024.
Replacing a word without touching the longer words that contain it, using whole-word
matching.
Supported input and output
Accepts
Plain text in the editor, plus a search term and a replacement string
JavaScript regular expression syntax, as supported by your browser’s engine
Produces
The rewritten text in the same box, with a count of replacements made
A downloadable text.txt, or the text copied to your clipboard
What this tool will not do
Replace all is the only action: no replace-one, no stepping through matches, no
highlighting of what is about to change. Run it and read the count, or undo.
Only two flags are used: global always, and case-insensitive when you clear the Case
sensitive box. There is no multiline, dot-all, sticky or unicode flag, and JavaScript
has no inline flag syntax, so a pattern beginning (?m) is rejected as an invalid group.
Without the multiline flag, ^ and $ anchor to the start and end of the whole text rather
than each line, and a full stop does not match a line break.
The guard catches patterns that will not compile, not patterns that are slow. One that
backtracks catastrophically still runs on the main thread and can lock the tab.
Replacement covers the whole text; there is no way to limit it to a selection, a line
range or the first few matches.
Common mistakes
Putting a dollar sign in the replacement and expecting it to be literal. The replacement
string is never escaped, even in literal mode, so $& inserts the matched text and $$
produces a single dollar sign — write $$ when you mean one.
Turning on Whole word for a term containing an accent or punctuation. Word boundaries
are ASCII-based, so searching for café or (cat) with Whole word on matches nothing and
reports zero replacements rather than an error.
Using Unicode property escapes in a pattern. Without the unicode flag \p{L} does not
mean ‘any letter’ — it matches the literal characters p{L}, so the replacement lands
somewhere you never intended.
Anchoring with ^ to prefix every line. It matches only the very start of the text, so
exactly one replacement is made and every other line is left alone.
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.