Format Code Now
/
TextFind and Replace Text Next: Slug Generator ›

Find and Replace Text

TX-15

Put a find line and a replace line at the top of the box, then your text below them. The tool replaces every match, with optional regular expressions, whole words and case-insensitive matching.

Runs in your browser. Nothing is uploaded.

Directive lines, then your text

Result

How to use it

  1. Start the input with a line "-- find: " followed by the text to look for.
  2. Add a line "-- replace: " with the new text. Leave it out to delete every match.
  3. Put the text to change on the lines below those directives.
  4. Tick Find is a regular expression, Ignore upper and lower case, or Whole words only as needed.
  5. Press Replace for the new text, or Count matches to see how many there are.

Why the settings are in the text box

This site's tools have one input box, so the find and replace texts go on the first lines: a line starting with -- find: and an optional line starting with -- replace:. Everything after them is your text. One space after the colon is ignored and other spaces are part of the value, so you can replace with a space or look for text with spaces. A missing replace line deletes every match. Only the leading directive lines are read, in either order.

Plain text and regular expressions

By default the find text is matched exactly as typed, special characters included, and the replacement is inserted literally, so a $ sign is just a dollar sign. With the regular expression option the find text is a JavaScript pattern, ^ and $ match at the start and end of every line, and the replacement can use $1 for a captured group, $& for the whole match and $<name> for a named group. Patterns run in Unicode mode, so some unnecessary escapes that JavaScript allows elsewhere are errors.

Whole words, case and counting

Whole words only means a match cannot touch a letter, digit or underscore on either side, so cat does not match inside category. Ignore upper and lower case matches Colour and colour alike, and the replacement is inserted exactly as you wrote it rather than copying the case of the match. Count matches gives the number of matches and leaves the text unchanged. A badly written pattern can make the browser slow on long text.

Error messages and what to do

MessageWhat it meansFix
Add a line that starts with "-- find:" before your text.The first line of the input is not a find directive, so the tool does not know what to look for.Start the box with -- find: and the text to search for, then add your text below it.
The find text is empty. Write what to look for after "-- find:".The -- find: line has nothing after the colon.Type the text or pattern to search for after -- find:.
Put the text to change below the directive lines.The box holds only the -- find: and -- replace: lines and no text under them.Add the text you want to change on the lines after the directives.

Questions people ask

How do I find and replace text online?

Start the box with a line -- find: followed by the text to find, then -- replace: followed by the new text, and put your own text on the lines below. Press Replace and every match is changed. Nothing leaves your browser.

How do I use regex in find and replace?

Tick Find is a regular expression and write a JavaScript pattern after -- find:. In the replacement you can use $1, $2 and so on for captured groups. For example, find (\w+)@example\.com and replace [email protected].

How do I delete every match instead of replacing it?

Leave out the -- replace: line, or write it with nothing after the colon. Every match is then removed from the text. Press Count matches first if you want to see how many matches there are before you remove them.

How do I replace only whole words?

Tick Whole words only. A match then cannot sit next to a letter, digit or underscore, so replacing cat does not change category or scat. It works with plain text and with regular expressions.

Does the replacement keep the capital letters of what it replaces?

No. With Ignore upper and lower case ticked, Colour and colour are both found, but they are both replaced with exactly the text you put after -- replace:. You can use a regular expression with groups if you need to reuse parts of the match.

How many matches will it change?

Every match in the text is replaced, not just the first. Press Count matches to see the total before you replace. Matches do not overlap, and the search works from left to right through the whole text.

About this tool

There is one input box, so the search settings go on the first lines of it: a line "-- find: text" and an optional line "-- replace: text". Everything after the last of those lines is the text to change. One space after the colon is dropped; any other spaces belong to the value. If there is no replace line, matches are deleted. In plain mode the find text is matched literally and the replacement is inserted as typed, including $ signs. With the regular expression option, the find text is a JavaScript pattern in Unicode mode, ^ and $ match at every line, and the replacement can use $1, $& and $<name> for captured groups. Because it uses Unicode mode, a few escapes that JavaScript allows elsewhere, such as \- outside a character class, are errors here. Whole words means the match cannot touch a letter, digit or underscore on either side. A badly written pattern can make the browser slow on long text. Count matches reports the number of matches and changes nothing. A text line that itself starts with "-- find:" or "-- replace:" directly after the directives is read as a directive.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.