1

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?

4

1 回答 1

2

Seems that you did everying correctly, but add Groups property

$line = 'Filename="Longfilename"'
$matches = [regex]::Match($line, 'Filename=\"(?<TheFilename>[^\"]+)\"')
$matches.Groups['TheFilename']
于 2012-07-23T03:56:13.997 回答