Re: Regex to match a numerical IP range



On 2010-12-14, Ted Zlatanov <tzz@xxxxxxxxxxxx> wrote:
On Mon, 13 Dec 2010 12:25:51 -0800 sln@xxxxxxxxxxxxxxx wrote:

s> On Mon, 13 Dec 2010 10:51:11 -0600, Ted Zlatanov <tzz@xxxxxxxxxxxx> wrote:
I think Net::Netmask is much better for this task than any custom
solution. Have you tried it?

s> Well, I thought it was just a case of knowing the simple ip
s> address without knowing anything about the CIDR network (block).
s> So given a simple quad part notation and range, a simple comparison
s> would be is all thats needed instead of a full blown cisco type thing.

I wouldn't try to write that code myself because the risk of getting it
wrong is too high. It's surprisingly hard to do IP ranges well,
especially if you need fast operations. But it looks so easy, doesn't it...

I added (??{}) for this, but it looks broken now:

perl -wle "123 =~ /^(\d+$)(??{ $1 > 122 ? qr( )x : qr((?!)) })/ or die"
panic: top_env

If I understand the docs correct, this should also work:

perl -wle "123 =~ /^(\d+$)(?(?{$1 > 122})|(?!))/ or die"

It looks like it works fine in 5.8.8 and 5.10.0.

Ilya
.



Relevant Pages

  • Re: Regex to match a numerical IP range
    ... s> address without knowing anything about the CIDR network. ... It's surprisingly hard to do IP ranges well, ... especially if you need fast operations. ...
    (comp.lang.perl.misc)
  • Re: Regex to match a numerical IP range
    ... s> address without knowing anything about the CIDR network. ... It's surprisingly hard to do IP ranges well, ... especially if you need fast operations. ...
    (comp.lang.perl.misc)
  • Re: Regex to match a numerical IP range
    ... s> address without knowing anything about the CIDR network. ... If I understand the docs correct, ... condition of the conditional expression extension. ...
    (comp.lang.perl.misc)