且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从一行中捕获多个正则表达式匹配到 Powershell 中的 $matches 魔术变量?

更新时间:2022-06-10 17:01:22

您可以像这样在 PowerShell 2.0 中使用 Select-String 来做到这一点:

You can do this using Select-String in PowerShell 2.0 like so:

Select-String F\d\d -input $string -AllMatches | Foreach {$_.matches}

不久前我有 要求在 MS Connect 上使用 -matchall 操作员,此建议已关闭,因为此评论已修复:

A while back I had asked for a -matchall operator on MS Connect and this suggestion was closed as fixed with this comment:

这是通过 -allmatches 参数为选择字符串修复的."

"This is fixed with -allmatches parameter for select-string."