Is there a shorter way to pull groups out of a Powershell regex?

后端 未结 3 709
星月不相逢
星月不相逢 2020-12-30 03:09

In PowerShell I find myself doing this kind of thing over and over again for matches:

some-command | select-string \'^(//[^#]*)\' |
     %{some-other-command         


        
3条回答
  •  一整个雨季
    2020-12-30 03:39

    You can use the -match operator to reformulate your command as:

    some-command | Foreach-Object { if($_ -match '^(//[^#]*)') { some-other-command $($matches[1])}}
    

提交回复
热议问题