Powershell -replace giving strange behaviour
问题 This is driving me nuts! Would appreciate any pointers as to what is going on, please! $alpha = 'aaa.bbb.$connection.ccc.ddd' $s = [regex]::match($alpha,"\$.+?(?=\.)").Value "Alpha is: $alpha" "Matched chunk is: $s" $newChunk = "'" + $s + "'" "New chunk is: $newChunk" $beta = $alpha -replace $s,$newChunk "Beta is: $beta" This produces the following output: Alpha is: aaa.bbb.$connection.ccc.ddd Matched chunk is: $connection New chunk is: '$connection' Beta is: aaa.bbb.$connection.ccc.ddd I am