The Regex to select what" /> The Regex to select what" /> The Regex to select what"/>

Powershell, how to exclude the "\" character in a Regex format

61 Views Asked by At

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.

0

There are 0 best solutions below