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

[FWP] IP address regex golf



> > 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.
> 
> Yes it is.  I have one now:
> 
> /^(\d|[01]?\d\d|2[0-4]\d|25[0-5])\.(\d|[01]?\d\d|2[0-4]\d|25[0-5])\.(\d|[01]?
> \d\
> d|2[0-4]\d|25[0-5])\.(\d|[01]?\d\d|2[0-4]\d|25[0-5])$/


/^((\d|[01]?\d\d|2[0-4]\d|25[0-5])\.){3}(\d|[01]?\d\d|2[0-4]\d|25[0-5])$/

or

/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/and$1<256and$2<256and$3<256and$4<256

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