⭐ 0

Replace in Text

Replace a literal or a /pattern/flags match, with an optional case-preserving replacement.

🔒 Processed entirely in your browser — nothing you enter here is ever uploaded.

The result appears on this page after you run the tool. Nothing you enter is uploaded.

Processing... 0%
Parsing input strings
Scanning search patterns
Applying replacements
Formatting output

Result

About this tool

Paste the text, type the find text and the replacement, and run it. The case-sensitive box starts checked, and the preserve-case box starts checked. A find string that does not begin with a slash is escaped and compiled as a global literal, or a global case-insensitive literal when the case box is cleared. A find string wrapped in slashes is compiled as a regular expression. Flags after the last slash are kept, i is added when the case box is cleared and i is missing, and g is added when the flags do not already contain it. Every match is considered. A pattern that fails to compile falls back to a literal global search of the whole find string.

Preserve case looks at the matched text, not at the replacement you typed. If the match is entirely uppercase and is not also entirely lowercase, the replacement is uppercased. If the match is entirely lowercase and is not also entirely uppercase, the replacement is lowercased. If the match is neither, but its first character is uppercase, only the first character of the replacement is uppercased and the rest is left as you typed it. Otherwise the replacement is inserted as typed. With the case box cleared and preserve case left on, the text Cat cat CAT and the replacement dog become Dog dog DOG. Cat takes the leading capital, cat stays lower, and CAT becomes DOG. Clear preserve case and the same three hits all become the exact replacement you typed.

The sentence-start and sentence-end boxes start off. They use the whole string, which is the difference from the search page. Sentence start keeps a replacement only when the trimmed text before that hit is empty or ends in a period, exclamation mark, or question mark. Sentence end looks at the trimmed text after the hit. A hit that fails the check is copied through unchanged. These tests are not limited to the current line, because the replacement runs on the full text and the offset is the offset in that full text. An empty find box does not wipe the text. The output is the original text. There is no preview of each hit and no count. The output box is the whole result. A replacement can be empty, which deletes the hits that pass the checks. The find text is not a list of words unless you write a pattern that matches a list. Nothing is uploaded. The search page is the one that reports line numbers and indexes. This page only writes the replaced text.

Example. Clear the case-sensitive box, leave preserve case on, find cat, and replace with dog. The text Cat cat CAT becomes Dog dog DOG.

Limit. Sentence-start and sentence-end tests use the full string. An empty find returns the original text. A pattern that does not compile is treated as a literal.

How does Cat cat CAT become Dog dog DOG?

Clear case sensitivity so all three match. Leave preserve case on and use the replacement dog. Cat is capitalized, so it becomes Dog. cat is lowercase, so it becomes dog. CAT is all capitals, so it becomes DOG.

What if I turn preserve case off?

Every accepted hit is replaced with the exact text you typed. Cat, cat, and CAT all become dog if that is the replacement. The case of the original match is ignored.

How is the sentence check different from search?

Search decides sentence start and sentence end inside one line. Replace looks at the trimmed text before and after the hit in the whole string. A hit that fails is left as it was.

What does an empty find box do?

The output is the original text. The page does not treat an empty find as 'match everything'. A find wrapped in slashes is a global regular expression, and g is added if you left it out.