鉴于此字符串和 PowerShell 2.0
Jrn.Grid "Control; Modal , Opening Worksets , Dialog_Revit_Partitions; Control_Revit_Partitions", "Selection" , "Rows;Shared Views, Levels, Grids;Shared Views, Levels, Grids;"
我正在尝试获取报价的最后一部分。我开始了
$string -match '(["])(\\?.)*?\1'
虽然$matches[0]
正确返回
"Control; Modal , Opening Worksets , Dialog_Revit_Partitions; Control_Revit_Partitions"
$matches[-1]
不返回"Rows;Shared Views, Levels, Grids;Shared Views, Levels, Grids;"
,奇怪的是$matches[1]
只返回一个双引号。我也试过$string -match '(["])(\\?.)*?\1$'
,用行尾锚点,然后 $matches[0] 返回引号中的所有内容。我怀疑我在测试嵌套引号时遇到问题,实际上我不想将它们视为嵌套的,我想将它们视为一个系列。我错过了什么,只获得最后一场比赛。而且,我该怎么做才能不在捕获中包含引号,它们之间有什么?
啊哈。基于 Toto 的示例,我添加了行尾锚点并使用了 $matches[1],因此
$string -match '"([^"]+?)"$'
$matches[1]
它似乎正在起作用。我希望我不会遇到任何更复杂的数据再次破坏它。
你可以使用:
$string -match '"([^"]+?)"'
那么比赛就在 $matches[1]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句