Regex Replace Tool

Find and replace with regular expressions and capture groups.

Free regex find-and-replace tool — test a regular expression against your text and apply a replacement with capture-group references like $1 and $2. Toggle global, ignore-case, multiline and dotall flags. Everything runs in your browser, nothing uploaded. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How do I reference capture groups in the replacement?

Use $1, $2 and so on for numbered groups, $& for the entire match, and $$ for a literal dollar sign — the same syntax as JavaScript String.replace.

A focused regex find-and-replace tool: enter a pattern, a replacement string, pick your flags, and watch the substituted output update live. Capture-group references let you reorder and reshape matched text — ideal for reformatting dates, cleaning data, bulk-editing code, and one-off text transformations.

How it works

The tool builds a JavaScript RegExp from your pattern and the flags you select, then runs String.replace against your input. In the replacement string you can use the standard substitution tokens: $1, $2 for the first, second numbered capture group, $& for the whole match, $<name> for a named group, and $$ for a literal dollar sign. The flags control matching: g (global) replaces every match instead of just the first, i ignores case, m (multiline) makes ^ and $ match at line breaks, and s (dotall) lets . match newlines. A live match count confirms how many replacements were applied.

Replacement token reference

TokenMeaningExample
$1, $2, …Numbered capture groups(\d+)$1
$&Entire matchprefix: $&_copy
$<name>Named capture group(?<year>\d{4})$<year>
$`Text before the matchrarely needed
$'Text after the matchrarely needed
$$Literal dollar signescape a $

Worked examples

1. Reformat ISO dates to day/month/year

  • Find: (\d{4})-(\d{2})-(\d{2}) (global flag on)
  • Replace: $3/$2/$1
  • Input: 2026-05-28 and 2025-12-01
  • Output: 28/05/2026 and 01/12/2025

2. Extract and reorder name parts

  • Find: (\w+),\s+(\w+) (global)
  • Replace: $2 $1
  • Input: Smith, John → Output: John Smith

3. Wrap all numbers in brackets

  • Find: \d+ (global)
  • Replace: [$&]
  • Input: There are 3 cats and 12 dogs.
  • Output: There are [3] cats and [12] dogs.

4. Strip HTML tags

  • Find: <[^>]+> (global)
  • Replace: “ (empty string)
  • Input: <b>Bold</b> and <i>italic</i>
  • Output: Bold and italic

Common mistakes to avoid

  • Forgetting the global flag — without g, only the first match is replaced. Turn it on for any bulk substitution.
  • Not escaping dots. matches any character in a pattern. A literal period needs \..
  • Using $1 when there is no group — if your pattern has no capturing parentheses, $1 pastes literally. Add a group around what you want to reference.
  • Confusing $& with $0 — JavaScript uses $& for the whole match, not $0 (which is not a valid token in the replacement string).

Patterns use the standard JavaScript engine, so what works here works in your code. Nothing is uploaded; all matching happens in your browser.