正则替换工具

实时高亮匹配并执行正则查找替换,支持捕获组反向引用。

//g
Replace with:
标志:global ·
测试文本0 字符

What Is the Regex Replace Tool?

The Regex Replace tool is an enhanced regular expression tester that combines real-time match highlighting with an inline find-and-replace engine. Type a pattern and a replacement string, paste your text, and instantly see both which parts match and what the output looks like after substitution. It supports all JavaScript regex flags and capture group back-references ($1, $2, $<name>) in the replacement string.

Use it to prototype regex replacements before integrating them into code, clean up text data, reformat strings, or extract and rearrange captured substrings.

How to Use the Regex Replace Tool

  1. Enter your regular expression pattern in the pattern field.
  2. Enter a replacement string. Use $1, $2 to reference capture groups, or leave empty to delete matches.
  3. Toggle flags (g, i, m, s, u) as needed.
  4. Paste or type your test string — the left panel highlights all matches in yellow.
  5. The right panel shows the result after applying the replacement.
  6. Click Copy Result to copy the replaced output, or Copy Matches to copy matched strings.

Features

  • Real-time match highlighting as you type
  • Side-by-side matched view and replaced output
  • Capture group back-references in replacement ($1, $2, $<name>)
  • Match details panel with index positions and named groups
  • Toggle g, i, m, s, u flags individually
  • Leave replacement empty to delete all matches
  • Copy result or copy all matches separately
  • Runs entirely in your browser — no data sent to servers

FAQ

How do I use capture groups in the replacement string?

Use $1, $2, etc. to reference numbered capture groups. For example, if your pattern is (\w+)\s(\w+), the replacement $2 $1 will swap the two words. For named groups (?<name>...), use $$<name> in the replacement.

What is the difference between Regex Replace and Regex Tester?

The Regex Tester only highlights matches and shows match details. The Regex Replace tool does everything the tester does, plus it applies a replacement string to produce a transformed output — useful for bulk find-and-replace operations.

What regex flags are supported?

g (global — replace all occurrences), i (case-insensitive), m (multiline — ^ and $ match line boundaries), s (dotAll — . matches newlines), u (Unicode mode). Toggle flags using the buttons above the test string.

How do I delete matched text?

Leave the replacement field empty. All matches will be replaced with an empty string, effectively deleting them from the output.