Regex Find & Replace

Run a find-and-replace using a regular expression pattern, with support for capture group references in the replacement text.

Text

Result, 2 replacements

Contact hello at example dot com or support at devtools dot com for help.

Example input

(\w+)@(\w+)\.com → $1 at $2 dot com

Example output

hello at example dot com

What is a Regex Find & Replace?

A regex find-and-replace does the same basic job as a plain text find-and-replace, but instead of matching one exact string, it matches an entire pattern, meaning one operation can rewrite many differently-formatted matches at once. Capture groups make this genuinely powerful rather than just a fancier search: parts of your pattern wrapped in parentheses can be referenced in the replacement text (typically as \$1, \$2, and so on), letting you rearrange, reformat, or partially rewrite matched text rather than just deleting or substituting it wholesale.

When to use it

This is the right tool when a plain find-and-replace isn't enough, reformatting a list of phone numbers into a consistent format, converting snake_case variable names to camelCase across a file, stripping a specific pattern like trailing whitespace or HTML tags from many lines at once, or restructuring log lines by rearranging captured pieces of each line. Testing the replacement here first, before running it against real code or data, catches a pattern that's slightly too broad (matching more than intended) or a capture group reference that's off by one, both easy mistakes that are much cheaper to catch in a preview than after overwriting a real file.

How it works

The tool applies your regex pattern against the input text using the global flag by default, so every match gets replaced, not just the first one. Wherever your replacement text includes \$1, \$2, etc., those get substituted with whatever text each corresponding capture group matched for that specific occurrence, this is standard JavaScript regex replacement behavior, so a pattern and replacement that work here will behave identically in actual JavaScript code using String.replace().

Frequently asked questions

Why isn't my replacement text showing the captured group values?

Double-check the reference syntax, capture groups are referenced as $1, $2, etc. (a dollar sign followed by the group number), not %1 or \1, which are the syntax used by some other regex tools and languages but not JavaScript's replacement syntax.

Why did my find-and-replace only change the first match?

This happens when the global (g) flag isn't applied, without it, most regex replace operations only affect the first match found rather than every occurrence in the text. This tool applies the global flag by default so every match gets replaced.

Can I use regex replace to reformat text, not just remove it?

Yes, this is where capture groups matter most. For example, matching a date like (\d{4})-(\d{2})-(\d{2}) and replacing it with $2/$3/$1 reformats YYYY-MM-DD into MM/DD/YYYY by rearranging the captured pieces, rather than just deleting or replacing the whole match with static text.