← Text

Find and Replace

Replace text with plain or regular-expression matching, case and whole-word options, capture groups, and a live highlighted preview.

Search

Options

Examples

Regex cheat sheet

.Any character except a line break
\d   \w   \sDigit; letter, digit, or underscore; whitespace (capitals negate)
^   $Start and end of text, or of each line in multiline mode
[abc]   [^abc]   [a-z]One character from the set, not in the set, or in the range
*   +   ?   {2,5}Repeat 0+, 1+, 0–1, or 2 to 5 times (add ? for the shortest match)
(a|b)Capture group with alternatives; refer to it as $1
(?<name>…)Named group; refer to it as $<name>
\.   \(   \$A literal special character

Text

Matches
0
Lines affected
0
Characters before
0
Characters after
0

Preview of the result

About this tool

This find and replace tool searches any pasted text and shows, as you type, how many matches there are and what the text will look like after replacement, with every changed segment highlighted. Plain mode treats the search term literally, so dots, brackets, and dollar signs need no escaping. Regular-expression mode unlocks patterns such as \d{4} for a year or (\w+)@(\w+) for an email address, and the replacement can refer back to captured groups with $1, $2, or

How it works

The search term is compiled into a JavaScript RegExp with the global flag, plus i for case-insensitive and m for multiline when selected; in plain mode every regex metacharacter in the term is escaped first. Matches are collected by stepping through the text, advancing one character after a zero-length match so patterns like ^ still terminate. For whole-word matching the character before and after each match is tested against the Unicode letter, digit, and underscore classes, so accented words and non-Latin scripts are handled correctly, unlike the ASCII-only \b. The result is assembled from the unmatched segments plus the replacement for each match; in regex mode the replacement template expands $1 to $99, Find and Replace Text Online: Regex, Case, Whole Word | HeroYears

← Text

Find and Replace

Replace text with plain or regular-expression matching, case and whole-word options, capture groups, and a live highlighted preview.

Search

Options

Examples

Regex cheat sheet

.Any character except a line break
\d   \w   \sDigit; letter, digit, or underscore; whitespace (capitals negate)
^   $Start and end of text, or of each line in multiline mode
[abc]   [^abc]   [a-z]One character from the set, not in the set, or in the range
*   +   ?   {2,5}Repeat 0+, 1+, 0–1, or 2 to 5 times (add ? for the shortest match)
(a|b)Capture group with alternatives; refer to it as $1
(?<name>…)Named group; refer to it as $<name>
\.   \(   \$A literal special character

Text

Matches
0
Lines affected
0
Characters before
0
Characters after
0

Preview of the result

and > Patterns use JavaScript regular-expression syntax; other engines such as PCRE or Python differ in a few details like \A or possessive quantifiers. Runs entirely in your browser; nothing you enter is sent anywhere. (text before and after), and $ for a literal dollar sign, while plain mode inserts the replacement verbatim. The preview marks up to 2,000 replaced segments, and a lines-affected count is taken from the line numbers of the matches.

Frequently asked questions

How do I use capture groups in the replacement?

Turn on Regular expression, wrap parts of the pattern in parentheses, and refer to them as $1, $2, and so on in the replacement. For example, find (\w+)@(\w+) and replace with $2 at $1 turns alice@example into example at alice. Named groups work too: (?<year>\d{4}) can be referenced as

What does whole word actually check?

A match counts only when the character immediately before and after it is not a letter, digit, or underscore. So searching for cat with whole word on matches cat in "the cat sat" and "a cat." but not inside concatenate or bobcat. The check uses Unicode categories, so café is treated as one word and the é does not create a false boundary the way the ASCII-only \b would.

Why does my regex show an error?

The pattern is compiled by the browser's regular-expression engine, and the tool translates its messages: unbalanced parentheses, an unclosed [ character class, a quantifier such as * or + with nothing before it, or a stray backslash at the end are the usual causes. To match a special character literally, put a backslash before it: \. for a period, \( for a parenthesis, \$ for a dollar sign, or switch off Regular expression to search for the text exactly as typed.

Can I replace across line breaks or add text to the start of every line?

Yes. With Regular expression and Multiline on, ^ matches the start of every line and $ the end, so finding ^ and replacing with "> " prefixes each line, and finding [ \t]+$ with an empty replacement strips trailing spaces. To match a line break itself, search for \n; to collapse blank lines, find \n{3,} and replace with \n\n. Without Multiline, ^ and $ refer only to the start and end of the whole text.

Related tools

Word Counter · Case Converter · Text Diff · Lorem Ipsum Generator · Slug Generator · Line Tools · Markdown Preview · Text Cleaner

Browse all Text Tools, or go back to every free tool on HeroYears.