regular expression on a range of number...

L

Louis

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
 
G

Gunnar Hjalmarsson

Louis said:
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]),/
 
L

Louis

Gunnar Hjalmarsson said:
/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
 
G

Gunnar Hjalmarsson

Louis said:
Gunnar said:
/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]),/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top