PowerShell, regex, Replace things that are not

Viewed 78

Using PowerShell I want to replace everything in a line in the file myFile.txt that is quoted in parenthesis that is not ("Sally") with ("Admin"). Is this the right way to do so, or is there a more appropriate way?

(Get-Content .\myFile.txt) -replace '\(\"(?!Sally).*\"\)', '("Admin")' | Set-Content .\myFile.txt

The contents of myFile.txt is:

("Bob")
("Sally")
("Tom")

And I'd like it to be:

("Admin")
("Sally")
("Admin")
0 Answers
Related