我试图解析字符串:使用-match
使用`提取两个字符串-match`
helo identity [email protected] Pass (v=spf1)
如下:
$line -match "helo identity (?<sender>.*) (?<heloresult>.*) (v=spf1)"
我认为这将返回:
$matches['sender'] = "[email protected]"
$matches['heloresult'] = "Pass"
但是,它返回$false
。
值得关注的是以下按预期工作:
$line -match "helo identity (?<sender>.*) Pass"
PS C:\> $matches
Name Value
---- -----
sender [email protected]
0 helo identity [email protected] Pass
我在做什么错误分配这两个部分?
我想你应该逃避'括号(V = SPF1)'正确的正则表达式是:'HELO标识( *( *?)? )\(v = spf1 \)' –
fardjad
我同意@fardjad,您应该将其作为答案发布。 – briantist