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

前端 未结 3 1021
情歌与酒
情歌与酒 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 12:03

    Do you want to get all occurances in the file? If so I would do the following

    $r = "^Task\((\d+)\)$"
    $res = gc myFile.txt | 
      ?{ $_ -match $r } |
      %{ $_ -match $r | out-null ; $matches[1] }
    

提交回复
热议问题