Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Regex replace by pattern.

$
0
0

Hi All,

 

I am trying to use regex in powershell 2.0 where  I need to find and replace a string by pattern. the string to be found is not know exactly, But need to find it by pattern matching and replace the matching pattern. Can you help me ? i googled a lot and the solution are bit tricky and confusing.

 

Find:

<add provider=iAnywhere.Data.SQLAnywhere;ENG=databaseengine01;DBN=useraccount25;INT=Yes;ASTOP=YES;LINKS=TCPIP(Host=192.168.1.0:2008;DoBroadcast=None;Verify=Yes);APP=EQUIP_SDK;PROWS=100;PBUF=256;COMP=YES&quot;" name="Entities" providerName="System.Data.EntityClient" />

Replace with:

<add provider=iAnywhere.Data.SQLAnywhere;;ENG=databaseengine10;DBN=useraccount100;INT=Yes;ASTOP=YES;LINKS=TCPIP(Host=192.168.1.10:2008;DoBroadcast=None;Verify=Yes);APP=EQUIP_SDK;PROWS=100;PBUF=256;COMP=YES&quot;" name="Entities" providerName="System.Data.EntityClient" />

 

In the above example, I need to replace the following  

ENG=databaseengine01 with ENG=databaseengine10

DBN=useraccount25 with DBN=useraccount100

Host=192.168.1.0 with Host=192.168.1.10

But these values are not fixed, it can be databaseengineXX useraccountXX 192.168.1.XX

So i need to find any occurring pattern of the above string and replace with new values. 


Viewing all articles
Browse latest Browse all 6937

Trending Articles