Regex Find and Replace

Replace with groups, without uploading anything.

Replace with groups, without uploading anything.

How to use it

  1. Write the pattern. Capture the parts you want to reuse in round brackets.
  2. Write the replacement. $1 and $2 for numbered groups, $<name> for named ones.
  3. Copy the result. The count of replacements is shown underneath.

When you would use this

A regular expression replace is the fastest way to restructure a block of text, and the part people look up every time is the replacement syntax. It is short: $1 is the first captured group, $2 the second, $<name> is a group you named, and $$ is a literal dollar sign. Leaving the replacement empty deletes every match, which is a real use rather than an accident. Global is a switch rather than an assumption. Replacing every match is usually what is wanted and replacing only the first is a genuine need, so both are one click apart instead of being buried in a flag string. The same backtracking protection as the tester applies here. A quantifier inside a quantified group is recognised before the pattern runs and refused on a long input, because JavaScript cannot interrupt a regular expression once it has started and the alternative is a frozen tab. Nothing is uploaded, which matters because the text being reshaped is usually the real thing rather than a sample.

Questions

How do I use a captured group in the replacement?
$1 is the first group, $2 the second, and $<name> is a group you named with (?<name>...). A literal dollar sign is written as $$. Leaving the replacement empty deletes every match, which is a legitimate thing to want.
What does turning off Global do?
It replaces only the first match instead of every one. That is the difference between the g flag being present or absent, and it is a switch here because both are wanted often enough.
Is my text sent anywhere?
No. It runs in the page, and that matters here more than almost anywhere else: the test string is by definition the data you are trying to match, which means people paste production log lines and real customer records into these boxes constantly.