BGP Regular Expressions
BGP Regular Expressions
? 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. You’ ll need this for BGP confederations.
Examples
^$ matches an empty AS PATH so it will match all prefxes from the local AS.
^100_ matches prefxes from AS 100 that is directly connected to our AS.
_100_ matches prefxes that transit AS 100.
_100$ matches prefxes that originated in AS 100, the $ ensures that it’ s the beginning of the AS PATH.
^([0-9]+)_100 matches prefxes from AS 100 where AS 100 is behind one of our directly connected AS’es.
^100_([0-9]+) matches prefxes from the clients of directly connected AS 100.
^(100_)+([0-9]+) matches prefxes from the clients of directly connected AS 100, where AS 100 might be doing AS PATH prepending.
^100_([0-9]+_)+ matches prefxes from the clients of directly connected AS 100, where the clients might be doing AS PATH prepending.
^\65200\) matches prefxed from confederation peer 65200.