I have a string:
<UserInputs><UserInput Question="Groupname" Answer="<Values Count="1"><Value DisplayName="AllHummanresources" Id="af05c5d3-2312-c897-8439-08979d4d0a49" /></Values>" Type="System.SupportingItem.PortalControl.InstancePicker" /><UserInput Question="Ausgabe" Answer="Namen" Type="richtext" /></UserInputs>
I want to trim the string to get as result "AllHummanresources". So I need the word between DisplayName="
and "
.
How can I achieve this goal? I did not find a fitting example in the net :(
greetings
CodePudding user response:
You could use the -replace
operator so that you omit everything apart from that string.
$string -replace '. (?:DisplayName=")(.*?)". ', '$1'
Granted this is only as good as the consistency of your input string.
CodePudding user response:
You can use Select-String
Cmdlet along with regex.
$result = $your_string | Select-String -Pattern "DisplayName="(.*?)""
If the match is successful you can access the group by
Write-Host $result.Matches.Groups[1].Value