04-23-2010 07:44 PM - edited 03-04-2019 08:16 AM
So, you can attach a multiplier to a multicharacter sequence like so:
(ab)+
That mean one or more occurences of the sequence "ab"
But what if I want to match on a string that does NOT have this sequence? Like I want to match on a static route in a configuration that does not contain a tag...
"ip route .* [^(tag)]"
But that doesn't work... how do you specify that a string that does not contain a multi-character sequence?
04-24-2010 01:55 AM
ringwyrm wrote:
So, you can attach a multiplier to a multicharacter sequence like so:
(ab)+
That mean one or more occurences of the sequence "ab"
But what if I want to match on a string that does NOT have this sequence? Like I want to match on a static route in a configuration that does not contain a tag...
"ip route .* [^(tag)]"
But that doesn't work... how do you specify that a string that does not contain a multi-character sequence?
Unfortunately the regular expression support in IOS is not like that of a scripting language like Perl/TCL. It is only a limited subset and there is no negation charater in that subset as far as i know.
Jon
04-24-2010 03:43 PM
According to documentation: You can reverse the matching of the range by including a caret (^) sign at the start of the range...The following example matches anything except a right square bracket (]) or the letter d: [^\]d]
So, maybe there is a problem with the meaning of the expression you have within brackets (i.e. the "^(tag)"). I am not sure exactly what this means in the context of a range enclosed within brackets. If you had [^tag] it would match anything except t or a or g. So, maybe could you try the following:
"ip route .*[^t][^a][^g].*"
After examining the syntax of the ip route command, I wonder whether you could have a "g" anywhere except within the word "tag". The only pitfalls I can think of now are: a name for the route that contains the letter "g" or a route via say some GigabitEthernet. So, maybe you could try the following:
"ip route ([^g])*" (i.e. no "g" anywhere)
or
"ip route (.*[^g]_)* (i.e. no "g" at the end of a word)
I must say I am not sure if any of the above will work, but it probably wouldn't hurt to try them out. Please let us know if any of those or something else worked for you.
04-24-2010 03:56 PM
Maria
Oops, i stand corrected. I though ^ could only be used as a start of line delimeter and not to negate with Cisco IOS. Thanks for correcting.
To the OP, apologies for the misleading information.
Jon
04-24-2010 04:13 PM
Don't be in a hurry my friend. I was about to edit my previous post!
After some thinking, the first suggestion ("ip route .*[^t][^a][^g].*") will probably not work, because it could match a route that contains a tag via the surrounding wildcards. A better one might be: "ip route .*[^t][^a][^g]_.*" (i.e. 3 last letters of a word cannot be tag)
As I said previously, I'm not sure about what exactly is going to happen with those suggestions, but maybe we can all learn if author tries them out and provides some feedback.
Edit: Ok, even the suggestion of this post needs additional thinking. Maybe "ip route (.*[^t][^a][^g]_)*" is better. Anyway, I'll wait for feedback before correcting myself again
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide