regexp problem

Discussion in 'Perl' started by Karuna, Oct 17, 2003.

  1. Karuna

    Karuna Guest

    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
     
    Karuna, Oct 17, 2003
    #1
    1. Advertising

  2. Karuna

    Andy Shitov Guest

    > 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);
    }
     
    Andy Shitov, Oct 17, 2003
    #2
    1. Advertising

  3. Karuna

    Andy Shitov Guest


    > 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");
     
    Andy Shitov, Oct 17, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Hurrell
    Replies:
    4
    Views:
    177
    James Edward Gray II
    Feb 14, 2007
  2. Mikel Lindsaar
    Replies:
    0
    Views:
    541
    Mikel Lindsaar
    Mar 31, 2008
  3. Joao Silva
    Replies:
    16
    Views:
    402
    7stud --
    Aug 21, 2009
  4. Uldis  Bojars
    Replies:
    2
    Views:
    213
    Janwillem Borleffs
    Dec 17, 2006
  5. Matìj Cepl

    new RegExp().test() or just RegExp().test()

    Matìj Cepl, Nov 24, 2009, in forum: Javascript
    Replies:
    3
    Views:
    201
    Matěj Cepl
    Nov 24, 2009
Loading...

Share This Page