in reply to Regex Question
G'day clegane,
This appears to do what you want:
$ perl -Mstrict -Mwarnings -le ' my $cell = <<EOD; <td> 1. Network-Time, Protocol: TCP, Source Port: 0-65535, Destination Port +: 13-13 2. Network-Time-1, Protocol: UDP, Source Port: 0-65535, Destination Po +rt: 13-13 3. Network-Time-2, Protocol: TCP, Source Port: 0-65535, Destination Po +rt: 37-37 4. Network-Time-3, Protocol: UDP, Source Port: 0-65535, Destination Po +rt: 37-37 5. Network-Time-4, Protocol: UDP, Source Port: 0-65535, Destination Po +rt: 123-123 </td> EOD my $re = qr{Protocol:\s+(\w+).*?Destination Port:\s+(\S+)}m; my @extract; push @extract, join(":", $1, $2) while $cell =~ /$re/g; print "@extract"; ' TCP:13-13 UDP:13-13 TCP:37-37 UDP:37-37 UDP:123-123
Notes:
-- Ken
|
|---|