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.

2
  • You already included the regex tag. So what did you try?
    – Daniel B
    Commented Aug 20, 2015 at 20:51
  • The code I pasted in from above is straight out of powershell. So, any seemingly Notepad++ tags in there is just coincidence.
    – Nex
    Commented Aug 20, 2015 at 21:32

1 Answer 1

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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .