Regular Expressions - Replacing Text
As we saw before, regular expressions can specify groups in the pattern to capture data from the text.
But these groups can also be used for replacing data in a given text.
Note: Be careful when doing replacement, as the whole match will be replaced. Make sure you capture text that should be kept in the replacement if it is part of the pattern
Backreferences can be used for replacement using the
$N syntax, where
N is the number of the captured group that you want to use for replacement.
If you want to use named capture groups, you need to use the following syntax