Question:
How to extract the number in the string “Task(12345)” with Regular Expression and Powershell? I tried the following, but no chance.
1 2 3 4 |
$file = gc myfile.txt $matches = ([regex]"Task\(\d{1,5}\)").matches($file) # Get a list of numbers |
Could someone please help me to find the correct regular expression?
Answer:
Do you want to get all occurances in the file? If so I would do the following
1 2 3 4 5 |
$r = "^Task\((\d+)\)$" $res = gc myFile.txt | ?{ $_ -match $r } | %{ $_ -match $r | out-null ; $matches[1] } |