Regex Replacer

Regex Replacer

Regex replace online free. Find and replace with regular expressions. Live preview, capture group support ($1, $2)—regex find and replace tool.

0 chars 0 lines
🔄

Find & Replace

Use regex patterns with capture group replacements

/ /

📝 Replacement Patterns

$1, $2 Capture groups
$& Entire match
$` Before match
$' After match
$$ Literal $
$<name> Named group

Features

  • Regex-powered find & replace with live preview
  • Global, case-insensitive, and multiline flag controls
  • Capture group references in replacements ($1, $2, $&)
  • Inline diff view with color-coded changes
  • Side-by-side original vs result comparison
  • Line-by-line diff for multi-line text
  • Apply changes in place (editable undo stack)
  • Pre-built replacement pattern templates

Common Use Cases

  • Reformat dates from YYYY-MM-DD to DD/MM/YYYY using capture groups
  • Bulk transform URLs or file paths with a single pattern
  • Sanitize or redact sensitive patterns in log files
  • Convert camelCase to snake_case or kebab-case
  • Remove duplicate whitespace, HTML tags, or boilerplate text

Regex Find & Replace

Regex replacements go beyond plain string substitution. Using capture groups, you can reference parts of the matched text in your replacement string.

In JavaScript's String.replace(), the replacement string supports special patterns: $1, $2, etc. for numbered capture groups; $<name> for named groups; $& for the whole match; $` for the text before the match; and $' for the text after the match.

This makes regex replacement a powerful transformation tool — not just for simple swaps, but for restructuring, reformatting, and annotating text programmatically.

Examples

Valid - Date reformat (YYYY-MM-DD → DD/MM/YYYY)
(\d{4})-(\d{2})-(\d{2}) → $3/$2/$1
Valid - Remove HTML tags
<[^>]+> → (empty)
Valid - Wrap emails in brackets
\b[\w.+-]+@[\w.-]+\.\w{2,} → [$&]
Valid - camelCase to snake_case
([A-Z]) → _$1 (then lowercase)

Frequently Asked Questions

How do I reference a capture group in the replacement?

Use $1 for the first group, $2 for the second, and so on. For named groups like (?<year>\d{4}), use $<year>. For example, pattern (\w+)@(\w+) with replacement $1 at $2 turns "john@example" into "john at example".

What does $& mean in the replacement?

$& represents the entire matched string. So a pattern \d+ with replacement [$&] would wrap every number in brackets: "Order 123" → "Order [123]".

Can I replace with an empty string (delete matches)?

Yes! Leave the replacement field empty. This effectively removes all occurrences of the pattern. For example, pattern <[^>]+> with an empty replacement strips all HTML tags.

What is the difference between the Preview, Side-by-Side, and Diff views?

Preview shows the final result text. Side-by-Side displays the original next to the result for easy comparison. Diff shows inline changes (strikethrough red for removed, green for added) and a line-by-line diff below, like a code review.

What is the "Apply Changes" button for?

It replaces the content of the input text area with the result, allowing you to chain multiple replacements. The Undo button lets you revert to the previous state. You can step through a series of transformations without losing your original text.

💡 Tips

  • Use the Diff view to sanity-check that only the intended text was changed before clicking Apply.
  • Chain replacements by clicking "Apply Changes" between each, using the Undo stack to backtrack if needed.
  • For reformatting dates or structured text, named capture groups (<code>(?&lt;year&gt;\d{4})</code>) make your replacement pattern self-documenting.
  • Test your replacement pattern on a small sample before running it on a large file.
  • To delete trailing whitespace from every line, use pattern <code>[ \t]+$</code> with the <code>m</code> (multiline) flag and an empty replacement.