BGP Regular Expressions Examples
BGP Regular Expressions Examples
Examples
Regular Expressions are used often for BGP route manipulation or filtering. In
this article well take a look at some useful regular expressions. First lets
take a look at the different characters that we can use:
Characters
? repeats the previous character one or zero times.
* repeats the previous character zero or many times.
+ repeats the previous character one or more times.
^ matches the beginning of a string.
$ matches the end of a string.
[] is a range.
_ matches the space between AS numbers or the end of the AS PATH list.
\\ is an escape character. Youll need this for BGP confederations.
Examples
^$
^51_
matches an empty AS PATH so it will match all prefixes from the local
AS.
matches prefixes from AS 51 that is directly connected to our AS.
_51_
_51$
matches prefixes that originated in AS 51, the $ ensures that its the
beginning of the AS PATH.
^([09]+)_51
^51_([09]+)
^(51_)+([0- matches prefixes from the clients of directly connected AS 51, where
9]+)
AS 51 might be doing AS PATH prepending.
^51_([09]+_)+
If you need some practice for these, I would suggest to use a BGP looking
glass server.
Got some more useful BGP regular expressions? please let me know!