in reply to Help on regular expressions

I see you don't need anything between ff:ff:ff:ff:ff:ff and xid, so this works:
my $line = "00:04:23:a5:ce:6d > ff:ff:ff:ff:ff:ff, ethertype IPv6 (0x8 +6dd), length 66: ::.61701 > ff02::1:2:.547: [udp sum ok] dhcp solicit + (xid=493907) (len12, hlim 255)"; my @match = $line =~ /^(\S+) > (\S+),.*IPv6.*\.547:\.*xid=(\d+)/; print "@match\n";
Update: You want to match IPv6 and .547, haven't read that.


Igor S. Lopes - izut
surrender to perl. your code, your rules.

Replies are listed 'Best First'.
Re^2: Help on regular expressions
by gargle (Chaplain) on Sep 21, 2005 at 14:52 UTC

    Hi,

    You might want to use the \\x trick:

    #!/usr/bin/perl use strict; use warnings; my $data; $data = '00:04:23:a5:ce:6d > ff:ff:ff:ff:ff:ff, ethertype IPv6 (0x86dd +), length 66: (hlim 255, next-header: UDP (17), length: 12) ::.61701 +> ff02::1:2:.547: [udp sum ok] dhcp solicit (xid=493907)'; if ($data =~ /^ (\S+)\s # i need this one \>\s (\S+),\s # this one as well \S+\sIPv6\s \( \S+ \),\s\S+\s\d+\:\s \( hlim\s\d+,\s next-header:\s\S+\s\(\d+\),\s length:\s\d+ \)\s (\S+)\s # just as this one \>\s (\S+)\s # this one \[udp\ssum\sok\]\sdhcp\ssolicit\s \( \S+\= (\d+) # and the final number \) /x) { print ">$1<\n"; print ">$2<\n"; print ">$3<\n"; print ">$4<\n"; print ">$5<\n"; }

    It makes the regex a little easier to understand.

    --
    if ( 1 ) { $postman->ring() for (1..2); }