Powershell: Using Regular Expression Reservation

How can I use regex to replace any text between quotation marks for an operator -replace? I can make it work with static text, but it can be almost any text.

Example:

$filecontent -replace 'AssemblyCopyright("text")', 'AssemblyCopyright("Copyright © 2016 myCompany")' | Out-File $file

given there AssemblyCopyright("text")can actually be anything including blank

AssemblyCopyright("")
+4
source share
1 answer

Try it like this:

... -replace 'AssemblyCopyright\("[^"]*"\)', 'AssemblyCopyright("Copyright © 2016 myCompany")'

Note that this assumes that the text inside the quotes does not contain another quote.


Example due to comment

GIF example

+3
source

Source: https://habr.com/ru/post/1654253/


All Articles