On Fri, 18 Feb 2005 13:14:28 -0500
rbt <[EMAIL PROTECTED]> wrote:
> Is it possible to use re.compile to exclude certain numbers? For
> example, this will find IP addresses:
>
> ip = re.compile('\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}')
>
> But it will also find 999.999.999.999 (something which could no
John Machin wrote:
Diez B. Roggisch wrote:
So I'd suggest you dump re and do it like this:
address = "192.168.1.1"
def validate_ip4(address):
digits = address.split(".")
if len(digits) == 4:
for d in digits:
if int(d) < 0 or int(d) > 255:
return False
re
>
> This approach would actually work without the need for subsequent
> validation, if implemented properly. Not only as you noted does it let
> "259" through, but also it doesn't cover 2-digit numbers starting with
> 2. Assuming excess leading zeroes are illegal, the components required
> are:
D
> The OP wanted to "find" IP addresses -- unclear whether re.search or
> re.match is required. Your solution doesn't address the search case.
> For the match case, it needs some augmentation. It will fall apart if
> presented with something like "..." or "comp.lang.python.announce". AND
> while I'm
Diez B. Roggisch wrote:
>
> You could use another regular expressin, e.g. like this:
>
>
> rex = re.compile(r"^((\d)|(1\d{1,2})|(2[0-5]\d))$")
This approach would actually work without the need for subsequent
validation, if implemented properly. Not only as you noted does it let
"259" through, bu
Diez B. Roggisch wrote:
> So I'd suggest you dump re and do it like this:
>
> address = "192.168.1.1"
>
> def validate_ip4(address):
> digits = address.split(".")
> if len(digits) == 4:
> for d in digits:
> if int(d) < 0 or int(d) > 255:
> return Fals
rbt wrote:
> Is it possible to use re.compile to exclude certain numbers? For
> example, this will find IP addresses:
>
> ip = re.compile('\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}')
>
> But it will also find 999.999.999.999 (something which could not
> possibly be an IPv4 address). Can re.compile be conf