1

Based to this Topic: How do I replace a line in a file using PowerShell?

<setting name="Media.MediaLinkServerUrl" value=" "/>

The Regex to select whatever inside: value=" and "/> is

$regex = '(?<=<setting name="Media\.MediaLinkServerUrl" value=")[^"]*'

It work well!

but what about if:

<setting name="Media.MediaLinkServerUrl" value=" \/>

I tried:

$regex = '(?<=<setting name="Media\.MediaLinkServerUrl" value=")[^\]*'

and

$regex = '(?<=<setting name="Media\.MediaLinkServerUrl" value=")[^\\]*'

but it doesn't work!

I know \ is an reserved regex character, but [^.]* or [^|]* for example work well.

So how to select between \ and \ with Regex in Powershell in the example above?

A Big thx!

Ps: I can't comment or ask on the original post because i don't have 50 reputation, sorry.

4
  • What does "doesn't work" mean? What's the expected outcome? Commented Feb 2, 2023 at 22:44
  • Your [^\\]* example does work and will match the space between " and \. aside from that, its not clear what the intent is Commented Feb 2, 2023 at 23:00
  • value=" isn't a valid attribute, because a closing " is missing. Commented Feb 2, 2023 at 23:17
  • Thx to Santiago Squarzon and mklement0 for your answers, you helped me to find the problem! Commented Feb 7, 2023 at 4:58

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.