in reply to IP Filtering RegEx needed

If you only want to match these IP's in the specified range you could use something like this:
my $regex = qr/(123\.145\.14[6-9]\.2)|(135\.168\.[1-9][0-9][0-5]?\.[0- +9][0-2]?[0-5]?)/o; print "$ip matched\n" if $ip =~ /$regex/;

Regards
Dietz

Update:
Added code below (see Re^4: IP Filtering RegEx needed)

Replies are listed 'Best First'.
Re^2: IP Filtering RegEx needed
by Fletch (Bishop) on Sep 15, 2004 at 14:37 UTC
    $ perl -le '$_="135.168.995.925"; print "Oops" if /135\.168\.[1-9][0-9 +][0-5]?\.[0-9][0-2]?[0-5]?/' Oops

    This is why it's really better to do the range checking outside the regex as others have mentioned.

    Update: As is remarked below, if you're sure you're not going to get bogus input from your data then this may not be an issue. It's just something to be aware of when you consider what solution to use (and to keep in the back of your mind for when something breaks and you get bogus results from something like this and can't figure out why . . . :).

      You're are absolutely right!

      OTOH in which log would you find addresses containing an octet with '995'

      My attempt was just a quick hack to serve the OP and is not fully tested, though I believe it's good enough to don't match other ranges, but I could be incorrect, and maybe I should have stated so :-(

      Thank you!
      Dietz

        My above code is absolute nonsense and was just a quick hack
        This should do it now on the specified ranges:
        my $regex = qr/ ( 123\.145\.14[6-9]\.2 # match first specified range | # or # second specified range: 135\.168\. # <= first 2 octets (?: # 3rd octet: 1 (?: 0[0-9]|1[0-5] ) # 100 - 109 or 110 - 115 | # or [1-9][0-9] # 10 - 99 ) \. # 4th octet: (?: (?:1[01][0-9]|12[0-5]) # 100 - 119 or 120 - 125 | # or [0-9][0-9]? # 0 - 99 ) $ # end of string ) /ox;

        I'm all puzzled now!

        Dietz