regular expression on a range of number...

Discussion in 'Perl' started by Louis, Jul 7, 2004.

  1. Louis

    Louis Guest

    hi all,

    i am setting up swatch (syslog monitoring) for email alert. i have a
    cisco 2924 switch and i wanna to ignore alarm from fastethernet0/0-22,
    but keep alarm on 0/23-24. i think the following statement works, but
    can i shorten the statement?

    /FastEthernet0\/[0-9],/ || /FastEthernet0\/1[0-9],/ ||
    /FastEthernet0\/2[01],/

    thanks
     
    Louis, Jul 7, 2004
    #1
    1. Advertising

  2. Louis wrote:
    > i am setting up swatch (syslog monitoring) for email alert. i have a
    > cisco 2924 switch and i wanna to ignore alarm from fastethernet0/0-22,
    > but keep alarm on 0/23-24. i think the following statement works, but
    > can i shorten the statement?
    >
    > /FastEthernet0\/[0-9],/ || /FastEthernet0\/1[0-9],/ ||
    > /FastEthernet0\/2[01],/


    /FastEthernet0\/(?:1?[0-9]|2[0-2]),/

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jul 7, 2004
    #2
    1. Advertising

  3. Louis

    Louis Guest

    Gunnar Hjalmarsson <> wrote in message news:<gBOGc.98024$>...

    > /FastEthernet0\/(?:1?[0-9]|2[0-2]),/


    Thanks a ton...

    I think I understand the last part '|2[0-2]'. Can you explain
    '?:1?[0-9]'? Or ':' -? '|'?

    Thanks
     
    Louis, Jul 8, 2004
    #3
  4. Louis wrote:
    > Gunnar Hjalmarsson wrote:
    >>
    >> /FastEthernet0\/(?:1?[0-9]|2[0-2]),/

    >
    > Thanks a ton...
    >
    > I think I understand the last part '|2[0-2]'. Can you explain
    > '?:1?[0-9]'? Or ':' -? '|'?


    (?: ) is to be seen together, and is for non-capturing grouping.

    But, honestly, there is absolutely no reason why I would try to
    explain regex syntax, since it's explained in the docs much better
    than I ever would be able to do. See for instance:

    http://www.perldoc.com/perl5.8.4/pod/perlretut.html

    P.S. You can shorten it with another three characters:

    /FastEthernet0\/(?:1?\d|2[0-2]),/

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jul 8, 2004
    #4
    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. VSK
    Replies:
    2
    Views:
    2,303
  2. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    851
    Alan Moore
    Dec 2, 2005
  3. Asen Bozhilov

    Regular expression 0 - number range.

    Asen Bozhilov, May 26, 2011, in forum: Javascript
    Replies:
    40
    Views:
    536
    Scott Sauyet
    Jun 13, 2011
  4. Frank Cui
    Replies:
    0
    Views:
    186
    Frank Cui
    Dec 20, 2013
  5. Frank Cui
    Replies:
    0
    Views:
    127
    Frank Cui
    Dec 20, 2013
Loading...

Share This Page