Reputation: 76
I need to write a regex to update some registry files for work for an upcoming migration
I have to dynamically update all strings in files where:
I have got it doing 1 and 2, but not 3 and 4. I'm using PowerShell 4.0, recursively checking files in a directory and producing a new file with the changes for each file found in each subdirectory.
The conversion should look like:
FROM: setting1="\"C:\\\\this\\\\is\\\\\adirectory\""
TO: setting1="\"O:\\\\\New_Directory_Path\""
FROM: othersetting="\"C:\\\\this\\\\abc\\\\directory""
TO: UNCHANGED
FROM: thisfile="\"(C:\\\\this\\\\directory\\\\somefile.some_ext)""
TO: thisfile="\"(O:\\\\New_Directory_Path\\\\somefile.some_ext)""
I'm at my wits end on this one, this is what I have so far, in terms of regex:
gc $file | % {$_ -replace "C:(?!.*abc.*)(?!.*xyz.*)(?!.*\..*).*","O:\\\\New_Directory_Path\"} | out-file "$filePath\$newFileName"
Hoping someone on here can lend a hand. Also, this is my first time posting on here, sorry for not putting my code in tags.
Upvotes: 0
Views: 28
Reputation: 7948
try this pattern
Edited:
C:(?!.*(abc|xyz)).*?(?=[^\\]+\.[^\\]+|$)
Upvotes: 1