Autonomous System Expressions

The AS-path keyword uses a regular expression string to match against the autonomous system (AS) path. AS Regular Expression Notation lists the regular expressions that can be used in the match conditions for BGP AS path and community. It also shows examples of regular expressions and the AS paths they match.

Table 1. AS Regular Expression Notation
Character Definition
N As number
N1 - N2 Range of AS numbers, where N1 and N2 are AS numbers and N1 < N2
[Nx ... Ny] Group of AS numbers, where Nx and Ny are AS numbers or a range of AS numbers
[^Nx ... Ny] Any AS numbers other than the ones in the group
. Matches any number
^ Matches the beginning of the AS path
$ Matches the end of the AS path
Matches the beginning or end, or a space
- Separates the beginning and end of a range of numbers
* Matches 0 or more instances
+ Matches 1 or more instances
? Matches 0 or 1 instance
{ Start of AS SET segment in the AS path
} End of AS SET segment in the AS path
( Start of a confederation segment in the AS path
) End of a confederation segment in the AS path
Table 2. Policy Regular Expression Examples
Attribute Regular Expression Example Matches
AS path is 64496 “64496” 64496
Zero or more occurrences of AS number 1234 “64496*”

64496

64496 64496

Start of AS path set “64496 64500 { 64505”

64496 64500 64505 { 64511

64509 64496 64500 { 64505 64507

End of AS path set “64500 } 64505” 64500 } 64505 56
Path that starts with 99 followed by 34 “^64511 64505 “ 64511 64505 45
Path that ends with 99 “64511 $” 45 66 64511
Path of any length that begins with AS numbers 64496 64497 64498 “64496 64497 64498 .*” 64496 64497 64498 64499 64500 64501 64502 64503 64504
Path of any length that ends with AS numbers 64496 64497 64498 “.* 64496 64497 64498 $” 64496 64497 64498 64502 64503 64504 64496 64497 64498

Following are additional examples of using regular expressions in the AS-Path statement.

The following AS-Path statement matches AS paths that contain only (begin and end with) AS number 64511:

as-path "^64511$"    

The following AS-Path statement matches AS paths beginning with AS number 64500, ending with AS number 64511, and containing no other AS paths:

as-path "^64500 64511$"

The following AS-Path statement matches AS paths beginning with AS number 64496, followed by any AS number from 65500 - 65505, and ending with either AS number 65507, 65509, or 65511:

as-path "^64496 65500-65505 [65507 65509 65511]$"

The following AS-Path statement matches AS paths beginning with AS number 65511 and ending with any AS number from 65500 - 65505:

as-path "65511 [65500-65505]$"

The following AS-Path statement matches AS paths beginning with AS number 65511 and ending with any additional AS number, or beginning and ending with AS number 65511:

as-path "65511 .?"