Skip to content

Regex Replace

Rewrite text with a regex pattern and a replacement template that can reuse the captured pieces.

Processed locally in your browser

Options

g global · i ignore case · m multiline · s dotAll · u unicode · y sticky · d indices

0 chars · 0 lines
The result will appear here.

What is Regex Replace?

Regex Replace substitutes every match of a pattern with a replacement string. Unlike a plain find-and-replace, the replacement can reuse what was captured: $1 and $2 insert numbered groups, $<name> inserts a named group, $& the whole match, $` and $' the text before and after it, and $$ a literal dollar sign.

It is built for reformatting: swapping "Last, First" into "First Last", converting dates, wrapping numbers, stripping tags or normalizing separators. A table lists the first 100 replacements (position, original and new text) so you can check the effect, and the replacement count is shown. The pattern runs in a worker with a 5-second limit and is limited to 2,000 characters.

How does it work?

  1. Enter the pattern and the flags (g replaces all matches, gm makes ^ and $ work on each line).
  2. Write the replacement using $1, $2, $<name> or $&. \n and \t insert a line break and a tab.
  3. Paste the text, check the preview table and the count, then copy the result.

Common use cases

  • Reordering names, dates or codes with capture groups (2024-01-15 → 15/01/2024).
  • Adding quotes, brackets or prefixes around every number or word.
  • Removing HTML-like tags, comments or trailing whitespace across many lines.
  • Refactoring identifiers in pasted code with a systematic pattern.

Examples

Try this input in the tool above:

John Smith
Jane Doe
Ada Lovelace

Privacy

Regex Replace runs entirely in your browser. The text or files you provide are processed on your device and are not uploaded, logged or stored on our servers.

Limitations

Only JavaScript syntax and replacement templates are supported. Without the g flag only the first match is replaced.

Frequently asked questions

How do I keep a dollar sign in the replacement?

Write $$. A single $ followed by something that is not a group reference is kept as is.

How does this differ from Find and Replace?

Find and Replace is a general text tool with plain-text mode and match-case options. Regex Replace is regex-only, exposes every flag, and shows each replacement in a table.

What does an empty match do?

A pattern that can match nothing, such as x*, matches between every character, so the replacement is inserted at each position.

More tools in Developer Tools →