Jump to content

_ReplaceStringInFile() RegEx version?


Recommended Posts

I was working on something last night and decided to use StringRegExpReplace() for a config file, I never noticed that you cant just "overwrite" the file with the update so easily it required a few more pieces of code to work properly.

Is this the simplest way (what I used) and while I searched for it and did not find it do we have or will we have a RegEx equivalent for _ReplaceStringInFile()?

$sFile = FileRead(@ScriptDir & "\test.txt")
$hFile = FileOpen(@ScriptDir & "\test.txt", 2)
$sNewContent = StringRegExpReplace($sFile, "(test)", "new$1")
FileWrite($hFile, $sNewContent)
FileClose($hFile)

 

Link to comment
Share on other sites

What I am asking is if you need regex, is what I posted above account for the simplest way to accomplish the same task but with regex capability.  

My config file did not have a static string, it has varying length and values so I needed regex to ensure capture/replacement (IP Address + NIC Adapter)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...