Hi Glenn,
I have worked on this further and looked at some of the previous posts.
I have tried this with all different combinations of ip address and this has
worked.
Of course I got the idea from a previous post from Alex and Mark Thomas.
Please understand I could have just copied and pasted Mark's solution but
then I wouldn't have learned anything.

if($num =~ /^(([0-1]{0,1}[0-9]{0,1}[0-9]|2[0-4][0-9]|25[0-5])\.?){4}$/)

I feel that Mark's post is the better choice though and much
slicker than mine.

my $octet = qr/\d|[01]?\d\d|2[0-4]\d|25[0-5]/;
my $valid_ip = qr/^$octet\.$octet\.$octet\.$octet$/o;

print "yes" if $ip =~ $valid_ip;




----- Original Message ----- 
From: "Glenn Linderman" <[EMAIL PROTECTED]>
To: "Jamie Murray" <[EMAIL PROTECTED]>
Cc: "$Bill Luebkert" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Tuesday, January 13, 2004 6:24 PM
Subject: Re: REGEX help!


> On approximately 1/13/2004 6:49 AM, came the following characters from
> the keyboard of Jamie Murray:
> > Hi guys,
> >  I have seen my error which I have overlooked and don't mind admitting
it.
> > : )  Course don't hold it against me cause I'm just eager to learn
> > and try things out.
> > My regex works it matches exactly what I want but not all possibilities
.
> >  I overlooked the simple fact that alex wants not 0 or 2 or 5 or 4 but
254
> > or less.
> > Course with the example I posted Alex can easily adjust for this.
> >
> > So my method excludes 65 and up ,165 and up but not 254 to 200 or 154 to
100
> > or 54 or less.
> > So yes Bill im excluding 192 amongst others in my regex I see your
point.
> > Ok so this gets a little deeper than expected because I can have 199 but
not
> > 299
> >
> > /^([0-1]{0,1}[0-9][0-9] | 2[0-4][0-9] | 25[0-5])\. ([0-1]{0,1}[0-9][0-9]
|
> > 2[0-4][0-9] | 25[0-5])\. ([0-1]{0,1}[0-9][0-9] | 2[0-4][0-9] |
25[0-5])\.
> > ([0-1]{0,1}[0-9][0-9] | 2[0-4][0-9] | 25[0-5]) $/
> >
> > so now we are checking for 000 or 00 to 199 or 200 to 249 or 250 to 255
> > followed by \.
> >  Now I should have this right. Making mistakes sure helps you learn and
> > think things through more thoroughly.
> >
> > How is that or do you have anymore suggestions.
>
> As someone else pointed out, you are rapidly approaching the REGEX given
> in the Perl Cookbook.  Once you add a case to handle single digit
> numbers you will be there.
>
> The only other differences are that you are using {0,1} which is exactly
> the same as ?, and you are using [0-9] which is exactly the same and \d.
>   In both cases, the latter of the two equivalent expressions is shorter
> to express, and used by the REGEX in the Perl Cookbook.
>
> >
> >
> > ----- Original Message ----- 
> > From: "Jamie Murray" <[EMAIL PROTECTED]>
> > To: "$Bill Luebkert" <[EMAIL PROTECTED]>;
> > <[EMAIL PROTECTED]>
> > Sent: Tuesday, January 13, 2004 9:40 AM
> > Subject: Re: REGEX help!
> >
> >
> >
> >>BiLL,
> >>If you check my second post I made the correction but I'm still correct
in
> >>my example and method.
> >> Actually the e-mail from Raul Davletshin pretty much verifys what I had
> >>also stated and he's also correct.
> >>As for explaining [0-2]  0 or 1 or 2 are all possibilities of course but
> >>only one(unless using ? but thats another story)
> >> so wheres the problem your explaining something we already know.
> >>Also the example I gave Alex can be adjusted to his needs using class []
> >>and range {}. At least he will know how to put together
> >>some type of expression that works instead of just relying on built in
> >>functions.
> >>As for your post down below you can check numbers that way.
> >>Did you run this in a script before you decided it doesn't work because
it
> >>worked perfectly for me.
> >>Please run what I have below and correct what is "actually incorrect"
not
> >>what you "think is incorrect"
> >> I'm all for learning and am just trying my best.
> >>
> >>Thanks!
> >>
> >>
> >>----- Original Message ----- 
> >>From: "$Bill Luebkert" <[EMAIL PROTECTED]>
> >>To: <[EMAIL PROTECTED]>
> >>Sent: Tuesday, January 13, 2004 5:07 AM
> >>Subject: Re: REGEX help!
> >>
> >>
> >>
> >>>Jamie Murray wrote:
> >>>
> >>>
> >>>>Hey Alex,
> >>>>I jumped a little quick there, the previous post does work but I had a
> >>
> >>doh
> >>
> >>>>moment and forgot your upper range match could only be 254 at most.
> >>>>Sorry about that.
> >>>>
> >>>>if($num =~
> >>>>
> >
> > /^[0-2][0-5][0-4]\.[0-2][0-5][0-4]\.[0-2][0-5][0-4]\.[0-2][0-5][0-4]$/)
> >
> >>>     ^^^  ^^^  ^^^
> >>>The digits can be 0-9, not 0-2, 0-4 or 0-5.  eg: 192.168.0.1 is a legal
> >
> > IP
> >
> >>>You can't check a number range this way.
> >>>
> >>>
> >>>> after each class [] use {num,num} to adjust for a part of the ip not
> >>
> >>having
> >>
> >>>>a number.
> >>>>
> >>>>so for example
> >>>>
> >>>>if($num =~
> >>>>
> >>
> >
/^[0-2]{0,1}[0-5][0-4]\.[0-2][0-5][0-4]\.[0-2][0-5][0-4]\.[0-2][0-5][0-4]$/)
> >
> >>>>matches ip's like these
> >>>> "three digit 254 or less"."three digit 254 or less"."three digit 254
> >
> > or
> >
> >>>>less"."three digit 254 or less".
> >>>>or
> >>>>"two digit 54 or less"."three digit 254 or less"."three digit 254 or
> >>>>less"."three digit 254 or less"
> >>>
> >>>
> >>>-- 
> >>>  ,-/-  __      _  _         $Bill Luebkert
> >
> > Mailto:[EMAIL PROTECTED]
> >
> >>> (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
> >>>  / ) /--<  o // //      Castle of Medieval Myth & Magic
> >>
> >>http://www.todbe.com/
> >>
> >>>-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers
stuff)
> >>>
> >>>_______________________________________________
> >>>Perl-Win32-Users mailing list
> >>>[EMAIL PROTECTED]
> >>>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> >>
> >>_______________________________________________
> >>Perl-Win32-Users mailing list
> >>[EMAIL PROTECTED]
> >>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> >>
> >
> >
> > _______________________________________________
> > Perl-Win32-Users mailing list
> > [EMAIL PROTECTED]
> > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> >
> >
>
> -- 
> Glenn -- http://nevcal.com/
> ===========================
> The best part about procrastination is that you are never bored,
> because you have all kinds of things that you should be doing.
>

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to