469,290 Members | 1,880 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

regexp problem

Hi
If I want to validate certain IP Address range
say in an IP Address range of : "15.70.186.15-100",
here where 15.70.186 is the network id and 15-100 is
the host id. I want to discover all IP Addresses that
fall in between 15.86.70.15 - 15.70.186.100 .
what regexp do i need to use ?

regds
kbs
Jul 19 '05 #1
2 2610
> If I want to validate certain IP Address range
say in an IP Address range of : "15.70.186.15-100",
here where 15.70.186 is the network id and 15-100 is
the host id. I want to discover all IP Addresses that
fall in between 15.86.70.15 - 15.70.186.100 .
what regexp do i need to use ?


Do you really need to use regular expression? If in future you will
change IP range you should rewrite regex. Regexes are not too sutaible
to deal with range checking (it is possible but the expression is not
human-friendly).

I think the best is to write a two-line function such as

sub check_ip_range{
my @ip = $_[0] =~ /^15\.70\.186\.(\d+)$/;
return ($ip[3] >= 15 && $ip[3] <= 100);
}

Jul 19 '05 #2
If I want to validate certain IP Address range
say in an IP Address range of : "15.70.186.15-100",
here where 15.70.186 is the network id and 15-100 is
the host id. I want to discover all IP Addresses that
fall in between 15.86.70.15 - 15.70.186.100 .
what regexp do i need to use ?


Do you really need to use regular expression? If in future you will
change IP range you should rewrite regex. Regexes are not too sutaible
to deal with range checking (it is possible but the expression is not
human-friendly).

I think the best is to write a two-line function such as
sub check_ip_range{
my ($ip) = $_[0] =~ /^15\.70\.186\.(\d+)$/;
return ($ip >= 15 && $ip <= 100) ? "+" : "-";
}

print check_ip_range ("15.70.186.90");

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Magnus Lie Hetland | last post: by
reply views Thread by Ed Leafe | last post: by
10 posts views Thread by Andrew DeFaria | last post: by
6 posts views Thread by Mark Findlay | last post: by
1 post views Thread by geos | last post: by
6 posts views Thread by Christoph | last post: by
7 posts views Thread by Csaba Gabor | last post: by
4 posts views Thread by r | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.