>-----Original Message----- >From: John W. Krahn [mailto:jwkr...@shaw.ca] >Sent: Tuesday, November 30, 2010 12:47 AM >To: Perl Beginners >Subject: Re: regexp matching nummeric ranges
>As Rob said [2..254] is a character class that matches one character (so >"127.0.0.230" should match also.) You also don't anchor the pattern so >something like '765127.0.0.273646' would match as well. What you need >is something like this: >#!/usr/bin/perl >use strict; >use warnings; >my $ip = '127.0.0.255'; >my $IP_match = qr{ > \A # anchor at beginning of string > 127\.0\.0\. # match the literal characters > (?: > [2-9] # match one digit numbers 2 - 9 > | # OR > [0-9][0-9] # match any two digit number > | # OR > 1[0-9][0-9] # match 100 - 199 > | # OR > 2[0-4][0-9] # match 200 - 249 > | # OR > 25[0-4] # match 250 - 254 > ) > \z # anchor at end of string > }x; >if ( $ip =~ $IP_match ) { > print "IP Matched!\n";; >} >else { > print "No Match!\n"; >} Thanks for all the good pointers... This is something I can work with! Marco. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/