The important concept to take away from this is negation: (\S+) matches anything but whitespace, ([^:]+) matches anything up to a colon. I stored the two IP addresses in an array, your mileage will vary. Also, (update here) any complex regex such as this one should use the x modifier so it can be segmented and commented.use strict; use warnings; use Data::Dumper; my $str = 'May 16 11:17:12 system app: [id:id:id] Message [Class] [Pri +ority:] {TCP} 111.1.1.64:1863 -> 222.2.2.155:55527'; # no need to use $1 $2 etc. when you can name them ;) my ($mon,$day,$time,$app,$id,$msg,$proto,@ip) = $str =~ / # example match (\S+)\s+ # May (\S+)\s+ # 16 (\S+)\s+ # 11:17:12 ([^:]+):\s+ # system app (\S+)\s+ # [id:id:id] ([^\{]+) # Message [Class] [Priority] (\{[^\}]+\})\s+ # {TCP} (\S+) # 111.1.1.64:1863 \s+\-\>\s+ # (skip ->) (\S+) # 222.2.2.155:55527 /x; print "$mon, $day, $time, $app, $id, $msg, $proto, @ip\n";
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to (jeffa) Re: Variable Length Parsing
by jeffa
in thread Variable Length Parsing
by ACiD
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |