Using Regular Expressions
You can use regular expressions when defining AS-path access lists and community lists to more easily filter routes. A regular expression uses special characters—often referred to as metacharacters—to define a pattern that is compared with an input string.
AS-path Lists
For an AS-path access list, the input string is the AS path of the routes to which the list is applied via the route-map or neighbor filter-list commands. If the AS path matches the regular expression in the access list, then the route matches the access list.
Example
The following commands apply access list 1 to routes inbound from BGP peer 10.5.5.2. Access list 1 uses a regular expression to deny routes originating in AS 32.
host1(config-router)#neighbor 10.5.5.2 remote-as 32host1(config-router)#neighbor 10.5.5.2 filter-list 1 inhost1(config-router)#exithost1(config)#ip as-path access-list 1 deny 32$Community Lists
For a community list, the input string is the community attribute of the routes to which the list is applied via a route-map command. If the community attribute matches the regular expression in the community list, then the route matches the community list.
Example
The following commands apply route map 5 to routes forwarded to BGP peer 10.5.5.4. Route map 5 uses a regular expression to match community numbers ending with 305, setting the weight of matching routes to 150.
host1(config-router)#neighbor 10.5.5.4 remote-as 425host1(config-router)#neighbor 10.5.5.4 route-map 5 outhost1(config-router)#exithost1(config)#route-map 5 permit 10host1(config-route-map)#match community 305$host1(config-route-map)#set weight 150Community Numbers
When you use a regular expression to match a community number, use the appropriate format for the community number in the community list. If you issue the ip bgp-community new-format command, the community number has the format AA:NN where AA is a number that identifies the autonomous system, and NN is a number that identifies the community within the autonomous system. Otherwise, the community number is an integer in the range 1-4294967295.
Metacharacters
Each regular expression consists of one or more metacharacters and zero or more complete or partial AS or community numbers. Table 1-3 describes the metacharacters supported for regular expression pattern-matching.
Table 1-3 Supported regular expression metacharacters
Using Metacharacters as Literal Tokens
You can remove the special meaning of a metacharacter by preceding it with a backslash (\). Such a construction denotes that the metacharacter is not treated as a metacharacter for that regular expression. It is simply a character or token with no special meaning, just as a numeral has no special meaning. The backslash applies only to the character immediately following it in the regular expression.
On the ERX system, you are likely to do this only for the parentheses characters, ( or ). BGP indicates a segment of an AS path that is of type AS-confed-set or AS-confed-seq by enclosing that segment within parentheses.
Example
The following AS-path access list uses a regular expression to match routes having an AS-path attribute that begins with any AS-confed-set or AS-confed-seq:
host1(config)#ip as-path access-list 1 permit ^\(The following AS-path access list uses a regular expression to match routes having an AS-path attribute that ends with any AS-confed-set or AS-confed-seq:
host1(config)#ip as-path access-list 1 permit \)$The following AS-path access list uses a regular expression to match routes having an AS-path attribute that includes the specific AS-confed-set or AS-confed-seq, (100 200):
host1(config)#ip as-path access-list 1 permit \(100 200\)Regular Expression Examples
Table 1-4 shows some representative regular expressions that might be used in an AS-path access list or community list along with sample attribute values that match or do not match the regular expression.
Table 1-4 Sample regular expressions
For information on using AS-path access lists, see Access Lists on page 1-16. For information on using community lists, see Community Lists on page 1-30.