I have a value assigned to variable, trying to add this value to another varible inside some regular expressions.
$displayName= "revison"
$updateddisplayName = "updateddisplayName = "${$displayName}""
Write-Host "$updateddisplayName"
I am able to get the variable value with below but not getting expected result. Tried with some different regular expressions as well.
$updateddisplayName = "updateddisplayName = $displayName"
I tried with replace but looks use case of Regex is almost same so did not worked.
(Get-Content -Path $PSScriptRoot/text.txt -Raw) -Replace 'setDisplayName.*', 'updateddisplayName = "${$displayName}"' | Set-Content $PSScriptRoot/text.txt
OutPut expected is updateddisplayName = "${revison}"
${revison}
is valid variable and variables can expand in"
, you need to use'
(single quotes) instead$updateddisplayName = 'updateddisplayName = "${$displayName}"'
"$updateddisplayName = 'updateddisplayName = "${' + $displayName + '}"'
$displayName
while also keeping${
and}
if so then Mathias's answer solves that problem