Regex 使用Select字符串时正则表达式不匹配
我已经用以下代码验证了我的正则表达式是否正确:Regex 使用Select字符串时正则表达式不匹配,regex,powershell,select-string,Regex,Powershell,Select String,我已经用以下代码验证了我的正则表达式是否正确: #this is the string where I'm trying to extract everything within the [] $text = "MS14-012[2925418],MS14-029[2953522;2961851]" $text -match "\[(.*?)\]" $matches[1] 输出: True 2925418 MS14-012[2925418],MS14-029[2953522;2961851]
#this is the string where I'm trying to extract everything within the []
$text = "MS14-012[2925418],MS14-029[2953522;2961851]"
$text -match "\[(.*?)\]"
$matches[1]
输出:
True
2925418
MS14-012[2925418],MS14-029[2953522;2961851]
我想使用Select String获得结果,例如:
$result = $text| Select-String -Pattern $regex
输出:
True
2925418
MS14-012[2925418],MS14-029[2953522;2961851]
我还尝试了什么:
$result = Select-String -Pattern $regex -InputObject $text
$result = Select-String -Pattern ([regex]::Escape("\[(.*?)\]")) -InputObject $text
还有一些更多的变化,以及不同类型的“和”围绕正则表达式等等。我真的没有主意了
有人能告诉我为什么在我使用Select字符串时正则表达式不匹配吗?在管道输出到Get Member后,我注意到Select字符串返回一个MatchInfo对象,我需要访问MatchInfo.MATCHS属性才能得到结果。感谢Mathias R.Jessen给我提示!;)提示:管道输出到获取成员噢,我需要访问$results.Matches。谢谢!:)使用Matches属性获取成员,您应该已经够麻烦的了:-)“明天您可以接受自己的答案”我会尽快完成:)