Friday, December 26, 2008

Regular Expression Special Characters

As a reminder to my self, the regular expression special characters.

Character Meaning
^ Start of string
$ End of string
[] Range of characters
- Used to specify range ( i.e. [0-9] )
( ) Logical grouping
. Any single character
* Zero or more instances
+ One or more instance
? Zero or one instance
_ start or end of string, or space

Examples (ive only scratched the surface here!)

Example 1
Only allow routes originated by as 54
ip as-path access-list 1 permit _54$
ip as-path access-list 1 deny .*

Example 2
Only allow routes from as 54 and directly connected peer AS,s
ip as-path access-list 1 permit ^54_([0-9]+)?$
ip as-path access-list deny .*

Example 3
To match on any route that has transitioned through as 54.  i.e. one that originated in, passed through, or advertised by use

ip as-path access-list 1 permit _54_

In fact the _ (underscore) character permits a space, command, start of string, end of string or a bracket symbol.




A great way to test regular expression is via the command
show ip bgp regexp {expression}
N.B. to enable a ? to be entered in a command line precede with ctrl-V.



No comments: