Reputation:
I have a PowerShell script that gets part of a string between >
and <
:
$splitArray = "SomeText>MyVariable<SomeMoreText" -split ">",0
$string = $splitArray[1] -split "<",0
$MyVariable = $string[0]
Is there a more efferent way of getting the MyVariable
between the > <
?
Upvotes: 1
Views: 107
Reputation: 37790
You could use a regex replace:
$myVar = "SomeText>MyVariable<SomeMoreText" -replace '.+>(.+)<.+', '$1'
Upvotes: 3