Advertisement

Regex Replace Tool

Find and replace text with a regular expression: capture groups ($1, $<name>), flags, every match listed in a table. Uses the JavaScript regex engine.

Without the surrounding slashes.
$1, $2 … = groups, $<name> = named group, $& = whole match, $$ = a dollar sign.

Search text with a regular expression and replace every match — rearranging captured groups, ignoring case or working line by line — and see each match listed in a table. The tool runs your browser's own JavaScript regex engine, so the result is exactly what text.replace(/pattern/flags, replacement) returns in JavaScript.

How to use this tool

  1. Paste the text you want to edit.
  2. Enter the pattern without slashes, for example (\d{4})-(\d{2})-(\d{2}).
  3. Enter the replacement, using $1, $2 … for groups and $<name> for named groups.
  4. Press Calculate. Set the flags: Global replaces every match instead of only the first.

Formula

result = text.replace(new RegExp(pattern, flags), replacement)

In the replacement, $1 to $99 insert a numbered group, $<name> a named group, $& the whole match and $$ a literal dollar sign. A group that did not take part in the match inserts nothing. With the escape option on, \n becomes a line break and \t a tab. Calculation runs in a worker with a two-second limit.

Example

In "paid on 2026-02-03", the pattern (\d{4})-(\d{2})-(\d{2}) captures 2026 as group 1, 02 as group 2 and 03 as group 3, so the replacement $3/$2/$1 turns the date into 03/02/2026. On the sample invoice text all three ISO dates are rewritten in day/month/year order — 3 matches replaced — and the table shows each match, its position and its groups.

Frequently asked questions

Why was only the first match replaced?

The Global (g) flag is off. Without it, JavaScript replaces only the first match; the note under the result tells you how many matches were skipped.

How do I insert a literal dollar sign?

Write $$. For example, replacing \d+ with $$$& turns 20 into $20: $$ gives the dollar and $& the matched number.

Does this work the same way in Python or PHP?

Most patterns behave the same, but replacement syntax differs: Python's re.sub uses \1 and \g<name>, and PHP's preg_replace accepts $1 or \1. Python also writes named groups as (?P<name>…).

Why did a pattern time out?

Nested quantifiers such as (a+)+$ can take too long on near-matches. The tool runs in a worker and stops after two seconds. Simplify the pattern or use shorter text.

Sources

Last updated: 2026-10-30

Advertisement