我已经用这段代码验证了我的正则表达式是正确的:
#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
我想使用 Select-String 来获得我的结果,例如:
$result = $text| Select-String -Pattern $regex
输出:
MS14-012[2925418],MS14-029[2953522;2961851]
我还尝试了什么:
$result = Select-String -Pattern $regex -InputObject $text
$result = Select-String -Pattern ([regex]::Escape("\[(.*?)\]")) -InputObject $text
还有一些更多的变体以及不同种类的“和'围绕正则表达式等等。我真的没有想法......
谁能告诉我为什么当我使用 Select-String 时正则表达式不匹配?