[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: re question
From:       "Matt McCredie" <mccredie () gmail ! com>
Date:       2007-09-20 22:36:45
Message-ID: 9e95df10709201536w46b75a00gb42817b3777ff12d () mail ! gmail ! com
[Download RAW message or body]

On 9/20/07, Ricardo Aráoz <ricaraoz@gmail.com> wrote:
> Dan Bar Dov wrote:
> > I'm trying to construct a regular expression to match valid IP address,
> > without leading zeroes (i.e
> > 1.2.3.4 <http://1.2.3.4>, 254.10.0.0 <http://254.10.0.0>, but not
> > 324.1.1.1, nor 010.10.10.1 <http://010.10.10.1>)
> >
> > This is what I come up with, and it does not work.
> >
> > r'(^[12]?\d{0,2}\.){3,3}[12]?\d{0,2}'
> >
> > What am I doing wrong?
> > Any common knowledge IP matching RE?
> >
> > Thanks,
> > Dan
> >
>
> r'^[12]\d?\d?.\d{1,3}.\d{1,3}.\d{1,3}$'

so 299.999.999.999 is a valid IP and 34.0.0.1 isn't? Also, the "."s
need to be escaped. Otherwise they match ANY character.

Matt
-- 
http://mail.python.org/mailman/listinfo/python-list

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic