Re: Regex to match a numerical IP range
- From: Ilya Zakharevich <nospam-abuse@xxxxxxxxx>
- Date: Tue, 14 Dec 2010 19:53:11 +0000 (UTC)
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
.
- Follow-Ups:
- Re: Regex to match a numerical IP range
- From: sln
- Re: Regex to match a numerical IP range
- References:
- Regex to match a numerical IP range
- From: sln
- Re: Regex to match a numerical IP range
- From: Ted Zlatanov
- Re: Regex to match a numerical IP range
- From: sln
- Re: Regex to match a numerical IP range
- From: Ted Zlatanov
- Regex to match a numerical IP range
- Prev by Date: Re: code review - JSON parsing and data structures
- Next by Date: Re: code review - JSON parsing and data structures
- Previous by thread: Re: Regex to match a numerical IP range
- Next by thread: Re: Regex to match a numerical IP range
- Index(es):
Relevant Pages
|