This is the data I am trying to parse:
10.186.128.0/20 172.17.128.161 0 65000 8788
10.186.128.0/20 172.17.128.161 0 65000 878
10.186.128.0/20 172.17.128.161 0 65000 87
Ideally the output should match the IP address from the beginning of the line and also last 2 or 3 or 4 digits. Example desired output:
10.186.128.0/20 8788
10.186.128.0/20 878
10.186.128.0/20 87
I have regex that will match the IP address "10\.\d*\.\d*\.\d*\/\d\d"
And then I have second regex that will match the last 2 or 3 or 4 digits " \d{4}$| \d{3}$| \d{2}$"
Question is how to combine those two regex expressions in PowerShell to achieve desired result?
Thanks
$s -replace '^(10(?:\.\d+){3}/\d+)\s.*\s(\d+)$', '$1 $2'? Or do you mean the text contains lines that need to be extracted first?10\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{2}Select-String '(?m)^(10(?:\.\d+){3}/\d+)\s.*\s(\d+)\r?$' -input $txt -AllMatches | Foreach {$_.matches} | Foreach {$_.groups[1].value + " " + $_.groups[2].value}? Note the$txthere is a multiline string input. It outputs expected result in PS 6.1.3