cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2753
Views
20
Helpful
12
Replies

REGEXP doubt

I have a doubt in using regexp in my eem script. 

 

Can someone help me.

 

My Script:


event manager applet update-port-description
event neighbor-discovery interface regexp GigabitEthernet.* cdp add
action 1.0 cli command "enable"
action 2.0 cli command "config t"
action 3.0 cli command "interface $_nd_local_intf_name"
action 4.0 cli command "description $_nd_cdp_entry_name:$_nd_port_id [$_event_pub_time]"

 

Instead of applying this script to all the interfaces in my switch. 

I would like to apply this only for interfaces between gi0/[1-5] and not to any other interfaces.

 

Can someone help me in modifying the below line in the script,

event neighbor-discovery interface regexp GigabitEthernet.* cdp add 

 

Recommendations and suggestions are welcome !!!

12 Replies 12

Seb Rupik
VIP Alumni
VIP Alumni

Hi there,

Try this:

event neighbor-discovery interface regexp (GigabitEthernet0\/[1-5]\s) cdp add

cheers,

Seb.

This Didn't work.

 

Script didn't apply to any of the ports.

 

Regards,

Nishanth

hmmmm, maybe try it without the brackets:

 

event neighbor-discovery interface regexp GigabitEthernet0\/[1-5]\s cdp add

cheers,

Seb.

Yeah , I tried that without brackets.

 

Still the same.

maybe it doesn't like the escape character for the forward slash. try this one:

 

event neighbor-discovery interface regexp GigabitEthernet0.[1-5]\s cdp add

Still its a No.

 

 

 


interface regexp .*GigabitEthernet0/[0-9]+$ cdp add

 

This one worked, Still If I change the limit to gi0/[1-15] , It stopped working.

 

Check if you get some idea !

I didn't notice the .* you had at the beginning of the search. Does this work:

 

event neighbor-discovery interface regexp .*GigabitEthernet0.[1-5]\s cdp add

or

event neighbor-discovery interface regexp .*GigabitEthernet0/[1-5]\s cdp add

[0-15] won't work as it is not syntactically correct. Square brackets are for single character matches. If you wanted 0-15 you could use:

(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15)

or

([0-9]|[1][0-5])

event neighbor-discovery interface regexp .*GigabitEthernet0/[1-5]\s cdp add

event neighbor-discovery interface regexp .*GigabitEthernet0.[1-5]\s cdp add

 

Both didn't work,

 

Help me understand the below one and help me on extending that to gi0/[1-15]

 

 interface regexp .*GigabitEthernet0/[0-9]+$ cdp add

bah this is some poor mans regex support in EEM! I guess \s is not supported either!

 

try:

 

.*GigabitEthernet0/([0-9]|[1][0-5])+$

 

If that doesn't work I don't know what will. You can check everything I've offered is valid here:

www.regex101.com

 

regexxx.png

EEM regexp in the ED and in applets is limited to POSIX basic regexp support.  So to match a space, use [[:space:]].  The Perl-compatible \FOO will not work.

Hi Joe,

Do you have a link for the most authoritative Cisco doc on EEM equivalent regex voodoo??

 

cheers,

Seb.

In general, the syntax described at https://www.regular-expressions.info/posix.html will work within applets.  Tcl supports Tcl-compliant REs.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Innovations in Cisco Full Stack Observability - A new webinar from Cisco