Let's say I have a string:
$line = "name=""abc"""
I want to extract whatever is written within the quotation marks, like this:
[regex]::Matches($line,'(?<=name=").+?(?=")').Value
This works, but I want the word "name" to be passed as a variable to the regex, i.e. I have a variable $identifyer="name" and I want this to work:
[regex]::Matches($line,'(?<=$identifiyer=").+?(?=")').Value
but it does not work.
"..."strings (double-quoted aka expandable strings) perform string interpolation (expansion of variable values and expressions), not also'...'strings (single-quoted aka verbatim strings). With"..."quoting, if the string value itself contains"chars., escape them as`"or"", or use a double-quoted here-string. See the linked duplicate and the conceptual about_Quoting_Rules help topic.$line -replace "$identifier=`"(.+)`"", '$1'. If you want to rule out false positives and match the line in full:$line -replace "^$identifier=`"(.+)`"`$", '$1'