question

indus avatar image
indus asked indus posted

Applicability using wildcards and regex

I want to learn more about building reboust applicability strings for our response maps.

 

e.g. the following  command can be input in a variety of ways:

 

show ip interface ethernet 0/1

show ip interface eth0/1

sh ip int fa0/1

 

and so on....

 

Is there a tutorial/video or can someone build an applicability string?

 

I tried to use regex and did "sh.* int* (et*|fa*) \d+"

This matches "show ip int"  AND "show int".

 

Any help is appreciated.

iTestresponse map
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
PaulD avatar image
PaulD answered PaulD posted

This is where you need to learn some regex stuff.  (I realize that you are using iTest to avoid having to be a regex expert.  But if you're going to be the Response Mapping guru for your group, it will help you a lot of if you learn some regex basics.

 

In this case, the trick is to understand that .* in a regex will match anything.  But if you only want to match non-whitespace characters, you can use \S*.

 

So try this:

 

sh[ow]*\s+ip\s+int[erface]*\s+(et[hernet]*|fa[stethernet]*)\s*\d+/\d+

 

(I haven't tested this.)

 

You could just use \S* instead of [ow]* and [erface]*, etc., if you prefer.  

 

You can continue to adjust according to your needs.  

1 comment
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dclaar avatar image dclaar commented ·

Other tricks are to limit the number of characters in a match, and/or to tell it what not to match. For example, this RE matches "show interface", but not "show interface brief".

 

 

sh\w*\s+int\w{0,7}(?!\sb\w{0,4})

It translates to: "sh" followed by 0 or more word characters, followed by at least one space, followed by "int", followed by 0-7 characters (e.g. "erface"), and NOT followed by the group of ( a space, the letter b, and 0-4 letters).

 

 

 

 

 

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.