此问题已在此处有答案:
How to capture multiple regex matches, from a single line, into the $matches magic variable in Powershell?(4个答案)
昨天关门了。
我有下面的查询,我需要提取所有的列名更改,但如果我使用
$query = ",SELECT A.Title AS Identifier ,A.HOTELNAME AS PROPERTYNAME,A.REGION AS REGION,A.T0STATUS AS STATUS,"
$query -match ",.+ AS (.+),"
我只得到最后一个匹配的模式,捕获组的结果是Status,但我想要Identifier,PROPERTYNAME,REGION和STATUS。
所以基本上我的问题是如何使用正则表达式找到所有匹配而不是只有一个。
验证码:
",SELECT A.Title AS Identifier ,A.HOTELNAME AS PROPERTYNAME,A.REGION AS REGION,A.T0STATUS AS STATUS," -match ",.+ AS (.+),"
$matches
期望值:标识符PROPERTYNAME REGION STATUS。
结果:状态
另外,没有太多的文档专门用于PowerShell Regex,所以你也可以让我知道PowerShell使用哪种风格的regex。
1条答案
按热度按时间pkwftd7m1#
对于多个匹配项,您将需要
Select-String
cmdlet。标签:How to capture multiple regex matches, from a single line, into the $matches magic variable in Powershell?
关于regular expression,您可能希望使用Lookahead and Lookbehind