In that case you can split up the regex into multiple regex's and see if each one matches...
my $s = "tethereal (proto 6 or 17) and src host suntest1 and dst host
+suntest2 -w /tmp/dumpfile";
my %info;
$info{srchost} = $1 if $s =~ /\bsrc host (\S+)/;
$info{dsthost} = $1 if $s =~ /\bdst host (\S+)/;
$info{dir} = $1 if $s =~ /\b-w (\S+)/;
if( $s =~ /\(proto (.*?)\)/ ){ # this one needs extra processing
my $prot = $1; # start with the proto strin
+g: "6 or 17"
my @prot = $prot =~ /(\d+)/g; # pull out the integers:
+ (6, 17)
$info{protocol = join ',', @prot; # create the desired string:
+ '6,17'
}
# if necessary, validate %info here to make sure you can continue...
|