Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Regex backreference combined with string - how to separate

$
0
0

Hi, 

I'm doing a replace with a backreferencebut the backreference is being interpreted as part of the string instead. If I insert a space it is interpreted correctly but I do not want to have a space.

Here's the code:

$regex = '(<add key="Global.LoadBalancer.ServerFarmIPAddresses.CSV"\svalue=")(?:[^"]+)("\s/>)'
$fillerString = '$1127.0.0.1$2'

The expected result should be to change this string:

<add key="Global.LoadBalancer.ServerFarmIPAddresses.CSV" value="10.10.10.10,10.10.10.9,10.128.128.211,10.128.128.111" /> 

And change it to this one:

<add key="Global.LoadBalancer.ServerFarmIPAddresses.CSV" value="127.0.0.1" /> 

But instead it changes it to this:

    $1127.0.0.1" />    

How can I separate the $1 from the Ip address without adding a space?


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>