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

后端 未结 3 724
星月不相逢
星月不相逢 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:40

    You could try this:

    Get-Content foo.txt | foreach { some-othercommand [regex]::match($_,'^(//[^#]*)').value } 
    

提交回复
热议问题