The following Powershell replace operation with named groups s1 and s2 in regex (just for illustration, not a correct syntax) works fine :
$s -Replace "(?<s1>....)(?<s2>...)" '${s2}xxx${s1}'
My question is : how to replace with a variable $x instead of the literal xxx, that is, something like :
$s -Replace "(?<s1>....)(?<s2>...) '${s2}$x${s1}'
That doesn't work as Powershell doesn't replace variable in single quoted string but the named group resolution doesn't work anymore if replacement string is put in double quotes like this "${s2}$x${s1}".
"`${s2}$x`${s1}"
– user4003407