HandyBench

Find and Replace

Search and replace, with optional regex.

How to use the Find and Replace

  1. 1 Paste your text.
  2. 2 Enter the find and replace values; toggle regex or case-sensitivity if needed.
  3. 3 Copy the updated result.

How the search and replace behaves

Everything you type is turned into a JavaScript regular expression with the global flag, so every match in the text is replaced in a single pass. The "Case sensitive" box is off by default, which adds the i flag: searching for cat matches Cat and CAT too. The replacement is inserted as typed, so it does not copy the capitalisation of what it replaced.

  • Regex off: the find box is treated as plain text. Characters that are special in regular expressions, such as ., *, ? and (, are escaped for you, so a search for a.b only matches those three characters.
  • Regex on: the box is used as a pattern, with groups, classes and anchors. An invalid pattern shows an error message instead of changing your text.
  • The "Matches found" counter shows how many replacements were made.

Replacement tokens

These apply only when Regex is on, where the replacement follows JavaScript's rules: $1, $2 and so on insert capture groups, $& inserts the whole match, and $$ inserts a literal dollar sign. With Regex off, the replacement is inserted exactly as typed, so replacing a word with $1 or $& gives you those characters, not a group or the match.

Tested examples

GoalFind (regex on)ReplaceResult
Swap name order(\w+) (\w+)$2 $1John Smith, Jane Doe becomes Smith John, Doe Jane (2 matches)
Reformat a date(\d{4})-(\d{2})-(\d{2})$3/$2/$12024-03-15 becomes 15/03/2024
Lines to a list\n, a, b, c on separate lines becomes a, b, c
Squeeze spaces {2,}one spacex y z becomes x y z

Limits and gotchas

  • There is no multiline flag, so ^ and $ match only the very start and end of the whole text and not of each line. To add something to every line, use Add Prefix and Suffix to Lines instead.
  • The dot does not match line breaks, and there is no option to change that.
  • The tool replaces all matches at once. There is no way to step through them one at a time or to preview highlights, so check the counter before copying.
  • Greedy patterns such as .* can match far more than intended. Try a pattern in the regex tester first, and see the regex cheat sheet for the syntax.

Examples

  • ▸ "John Smith" with find (\w+) (\w+) and replace $2, $1 (regex on) → "Smith, John".
  • ▸ "2024-03-15" with find (\d{4})-(\d{2})-(\d{2}) and replace $3/$2/$1 → "15/03/2024".

Frequently asked questions

Does it support regular expressions?

Yes. Enable regex mode to use patterns, character classes and capture groups, and refer to groups as $1, $2 and so on in the replacement. $& inserts the whole match and $$ a literal dollar sign. With regex off, the replacement is inserted exactly as typed, so a price like $1 or a string like $& stays literal. An invalid pattern shows an error message instead of changing your text.

Is the search case sensitive?

Not by default. "Case sensitive" is unticked, so searching for cat also matches Cat and CAT, and every match is replaced with your replacement text. Tick the box to match only the exact capitalization.

How do I replace line breaks or tabs?

Turn on Regex and use \n for a line break or \t for a tab in the Find box. For example, finding \n and replacing it with a comma and a space turns a one-per-line list into a comma-separated line.

Why do ^ and $ only match at the start and end of the whole text?

The search runs without the multiline flag, so anchors apply to the whole text rather than each line. To add the same text to the start or end of every line, use the Add Prefix and Suffix tool instead.

Can I replace every occurrence at once?

Yes. All matches are replaced in one pass, so you can bulk-edit large blocks of text instantly instead of one at a time.

Is my text sent to a server?

No. Find and replace runs entirely in your browser, so the text you paste stays on your device.

Related guides