[英]How do I capture a value using Select-String and regex matching in PowerShell?
I'm trying to access the capture from a regex match using Select-String
. 我正在尝试使用
Select-String
从正则表达式匹配访问捕获。 Here's an example of the text. 这是文本的示例。
'dataarea' - closed, 10,933 rows are stored
I would like to capture the number of rows ( 10,933
). 我想捕获行数(
10,933
)。
PS> Select-String -Path $foo -Pattern 'closed,\s\d+[.,\d.*]{1,}' `
| %{ $_.Matches } `
| %{ $_.Value } > $output
I tried different regexes, but can't figure out how to capture just the number. 我尝试了不同的正则表达式,但无法弄清楚如何仅捕获数字。 This also captures the opening pattern,
closed
. 这也捕获了
closed
的打开模式。
Here's another possibility: 这是另一种可能性:
'(?<=closed.*)[0-9,]+'
so far, there's no guaranteed that comma will always be there, or there will always be only one. 到目前为止,不能保证逗号总是存在,或者永远只有一个。
无论有或没有昏迷,都可以分隔1000个:
$regex = '\d+[,|]+\d+'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.