[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] IP address regex golf



On Apr 28, Peter Scott said:
>At 06:55 PM 4/28/00 -0500, David L. Nicol wrote:
>> > > On 22-Mar-2000 George Bonser wrote:
>> > > > On Tue, 21 Mar 2000, William X. Walsh wrote:
>> > > >
>> > > > Anyone have an example of a working regex for perl to test for a 
>> valid IP
>> > > > address that they would be willing to share?
>> > >
>> > > That should be pretty easy. if a quad is >-1 and <256, it is a legal IP
>> > > address.
>>
>>  /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/and$1<256and$2<256and$3<256and$4<256
>
>   /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/&&!((1|$1|$2|$3|$4)&256)

A different flavor of the beast:

    do{$1>255||$b++>3and$a=1while/\G(\d+)(\.|$)/g;!$a};

-- 
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve             japhy@pobox.com
http://www.pobox.com/~japhy/                  http://pinyaj.stu.rpi.edu/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe