Regex Find and Replace Online

Replace every match of a regular expression in a text, with capture groups in the replacement and a preview of what changed.

Loading tool…

About the Regex Find & Replace

The pattern runs on the RegExp engine of your browser and the replacement follows the rules of String.prototype.replace(): $1…$99 insert a numbered group, $<name> a named group, $& the whole match, $` and $' the text before and after the match, and $$ a dollar sign. A reference to a group that does not exist is left as written. With the g flag every match is replaced, without it only the first; m makes ^ and $ match at each line, s lets . match line breaks, i ignores case, u enables \p{…} and y matches only at the start position.

JavaScript itself does not read backslashes in a replacement. With Escapes in replacement the tool adds them, as text editors do: \n, \t, \r, \\, \xHH and \u{…} insert a character, \U and \L turn what follows into upper or lower case until \E, and \u and \l change only the next character, so _([a-z]) → \u$1 converts snake_case to snakeCase. Plain text searches for the characters as typed and takes the replacement literally; Whole word skips matches that are part of a longer word.

The search runs in a Web Worker with a limit of 1.5 seconds and 20,000 matches: a pattern with catastrophic backtracking such as (a+)+$ is stopped with a message and the page stays responsive. Matches of length zero (^, \b, x*) are handled like in JavaScript, one per position. The two previews mark the matches in the input and the inserted text in the output. The text never leaves your browser.

How to use it

  1. Paste the text into Input.
  2. Type the pattern without slashes and tick the flags, or click a recipe.
  3. Type the replacement; leave it empty to delete the matches.
  4. Check the highlighted previews and the number of matches.
  5. Copy or download the output.

Frequently asked questions

How do I use a capture group in the replacement?
Put the part to keep in parentheses and refer to it by number: (\w+), (\w+) with the replacement $2 $1 swaps two words. Named groups (?<year>\d{4}) are inserted with $<year>.
How do I replace something with a line break or a tab?
Keep Escapes in replacement ticked and write \n or \t in the replacement. To match a line break in the pattern, use \n, or \r?\n for files with Windows line endings.
Why is only the first match replaced?
The g (global) flag is off. Without it JavaScript replaces the first match only, like replace() with a regex without g.
Is the syntax the same as in sed, Python or VS Code?
The patterns are JavaScript: the same as VS Code, and close to PCRE and Python for common patterns. Differences are in the replacement: JavaScript writes $1 where sed and Python write \1, and features like possessive quantifiers or \K do not exist. The \U, \L and \E operators work as in VS Code.

Related tools