How to extract the number in the string “Task(12345)” with Regular Expression and Powershell?

前端 未结 3 1028
情歌与酒
情歌与酒 2021-01-06 11:31

How to extract the number in the string \"Task(12345)\" with Regular Expression and Powershell? I tried the following, but no chance.

$file = gc myfile.txt
$         


        
3条回答
  •  难免孤独
    2021-01-06 11:49

    Keep in mind that Select-String makes this a one-liner:

    PS> Select-String 'Task\((?\d{1,5})\)' myfile.txt | 
            %{$_.matches[0].Groups['num'].value}
    

提交回复
热议问题