The following Powershell operation replaces the named groups s1 and s2 with regex (just for illustration and not for the correct syntax) works fine:
$s -Replace "(?<s1>....)(?<s2>...)" '${s2}xxx${s1}'
My question is: how to replace the variable $ x instead of the literal xxx, i.e. something like:
$s -Replace "(?<s1>....)(?<s2>...) '${s2}$x${s1}'
This does not work, since Powershell does not replace the variable in a single quote string, but resolving group names does not work anymore if the replacement string is placed in double quotes like this "$ {s2} $ x $ {s1}".
source
share