Notepad++ find and replace string or text with new string or text

1

I have some code several hundred lines long and I want to find each "String" and replace it with a different "String". Example below...

$BR360Button.Add_Click({BR360Button})

$BR368Button.Add_Click({BR368Button})

$BR370Button.Add_Click({BR370Button})

I want to find, ({BR360Button}) and replace with {(new-object -Com WScript.Network).RemoveNetworkDrive("M:"),(start-sleep 1),(new-object -Com WScript.Network).MapNetworkDrive("M:" , "\3600-co\data\store")}

Then find, ({BR368Button}) and replace with {(new-object -Com WScript.Network).RemoveNetworkDrive("M:"),(start-sleep 1),(new-object -Com WScript.Network).MapNetworkDrive("M:" , "\3680-co\data\store")}

Then find, ({BR370Button}) and replace with {(new-object -Com WScript.Network).RemoveNetworkDrive("M:"),(start-sleep 1),(new-object -Com WScript.Network).MapNetworkDrive("M:" , "\3700-co\data\store")}

and so on through the 900 lines. I really don't want to find/replace 900 times.

Any way to do this easily in notepad++?

Thanks in advance.

Nex

Posted 2015-08-20T20:49:22.667

Reputation: 13

You already included the regex tag. So what did you try? – Daniel B – 2015-08-20T20:51:56.880

The code I pasted in from above is straight out of powershell. So, any seemingly Notepad++ tags in there is just coincidence. – Nex – 2015-08-20T21:32:27.657

Answers

0

I want to find each "String" and replace it with a different "String"

  • Menu "Search" > "Replace" (or Ctrl + H)

  • Set "Find what" to [\(][\{]BR(.*?)Button[\}][\)]

  • Set "Replace with" to {(new-object -Com WScript.Network).RemoveNetworkDrive("M:"),(start-sleep 1),(new-object -Com WScript.Network).MapNetworkDrive("M:" , "\\\10-co\data\store")}

  • Enable "Regular expression"

  • Click "Replace All"

enter image description here

Before:

$BR360Button.Add_Click({BR360Button})
$BR368Button.Add_Click({BR368Button})
$BR370Button.Add_Click({BR370Button})

After:

$BR360Button.Add_Click{new-object -Com WScript.Network.RemoveNetworkDrive"M:",start-sleep 1,new-object -Com WScript.Network.MapNetworkDrive"M:" , "\3600-codatastore"}
$BR368Button.Add_Click{new-object -Com WScript.Network.RemoveNetworkDrive"M:",start-sleep 1,new-object -Com WScript.Network.MapNetworkDrive"M:" , "\3680-codatastore"}
$BR370Button.Add_Click{new-object -Com WScript.Network.RemoveNetworkDrive"M:",start-sleep 1,new-object -Com WScript.Network.MapNetworkDrive"M:" , "\3700-codatastore"}

Further reading

DavidPostill

Posted 2015-08-20T20:49:22.667

Reputation: 118 938