routeprotocol.com

BGP Regular Expressions

There can be instances where identifying all the networks from a certain provider may be too complicated or numerous, and a regular expression may be more suitable to filter all networks from a certain AS. Regular expression can be used for this.

Quick guide to regular expression

ModifierPurpose
_Matches a space
^Indicates the start of a string
$Indicates the end of a string
[]Matches a single character with a range of characters
Indicates a range of numbers in brackets
[^]Excludes the characters listed in the brackets
()Nesting of search patterns uses parentheses
|Acts as an OR logic to a query
.Matches a single character including space
*Matches zero or more characters, or pattern
+Matches one or more instances of the character, or pattern
?Matches one or no instances of the character, or pattern
Common regular expression modifiers

Examples of Common Regular Expressions in BGP

^$ – Local originating routes

permit ^205_ – Only routes from neighbour AS 205

permit _205$ – Only routes originating from AS205

permit _205_ – Only routes that pass through AS205

permit ^[0-9]+ [0-9]+ [0-9]+? – Routes with three or fewer AS_Path entries


Posted

in

, ,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.