4

How can I use a regular expression to replace any text between quotes for a -replace statement? I can get it to work with static text, but it could be virtually any text.

Example:

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

given the AssemblyCopyright("text") could actually be anything including blank

AssemblyCopyright("")

1 Answer 1

3

Try it like this

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

Please note however, that this will assume that the text within the quotes does not contain another quote.


Example due to comment

GIF example

Sign up to request clarification or add additional context in comments.

3 Comments

That's a lot closer that I have gotten. The only problem is there's an A character in front of the copyright. I think regex or powershell does NOT like the copyright symbol
I think that is an encoding issue on your side - I did a quick test within PoSh ISE with no issues - please see the GIF
I am looking into it now. I think you have certainly solved it. Just needs some polish! :D Thank you! :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.