Reputation: 1863
I have a string, $line, where the contents are:
Filename="Longfilename"
I am trying to work out a regex to extract the string. I tried this:
$line -match "Filename=\"(?<TheFilename>[^\"]+)\"
where I am trying to capture Longfilename into $matches['TheFilename']
Unfortunately, this doesn't work.
How do I do this? Where is my mistake?
Upvotes: 1
Views: 3021
Reputation: 8679
Seems that you did everying correctly, but add Groups
property
$line = 'Filename="Longfilename"'
$matches = [regex]::Match($line, 'Filename=\"(?<TheFilename>[^\"]+)\"')
$matches.Groups['TheFilename']
Upvotes: 2