< Free Open Study > |
A regular expression is a sequence of one or more characters that can be used for two general purposes. The first purpose is to reduce the output from various show commands. For example, if you wanted to view the routing protocols that are active on a router, you could use show running-config and scroll through the output until you came to the section of the configuration that contained the routing configurations. Or, you could use an output modifier with a regular expression to display only those lines containing a router configuration command: rtrA# show running-config include router router eigrp 1 router bgp 2 This code uses the output modifier include and the regular expression router to reduce the amount of output from the show running-config command. Each line of output from this command is examined, and if the pattern router is contained in the line, the line is displayed. You could use the same regular expression with a different output modifier to display the configuration, starting with the router configurations and everything that follows : p2# show running-config begin router router eigrp 1 network 10.0.0.0 network 172.17.0.0 ! router bgp 2 network 200.1.1.0 network 200.1.2.0 neighbor 10.1.1.2 remote-as 2 neighbor 172.17.1.2 remote-as 1 ! line con 0 exec-timeout 0 0 transport input none line aux 0 line vty 0 4 login ! end Having the capability to reduce the output of show commands is very useful with BGP. If your BGP routers contain the entire Internet routing table, using the show ip bgp command displays tens of thousands of routes. If you are interested in only a particular prefix, the use of a regular expression greatly reduces the amount of output: rtrA# show ip bgp include 200.1 BGP table version is 8, local router ID is 200.1.4.1 *> 200.1.1.0 0.0.0.0 0 32768 i *> 200.1.2.0 0.0.0.0 0 32768 i *> 200.1.3.0 0.0.0.0 0 32768 i *> 200.1.4.0 0.0.0.0 0 32768 I These regular expressions are simple character strings. Complex regular expressions can be constructed by using the characters A to Z, a to z, 0 to 9, and the special characters listed in Table B-1. Table B-1. Regular Expressions: Special Characters
Here are some examples:
If you want to use one of the special characters in Table B-1 as a regular character, precede it with a backslash (\). For example, \$ matches the dollar sign character, \+ matches the plus sign character, and \_ matches the underscore character. Square brackets are used to specify a range of single characters. Here are some examples:
Obviously, you can get carried away with the complexity of a regular expression. The second general purpose of the regular expression is in an autonomous system path filter. BGP can filter incoming or outgoing updates based on the AS path information.A BGP router prepends its own AS number on the AS path list for every prefix that is advertised. Table B-2 lists common regular expressions for use in AS path filters. Table B-2. Common Regular Expressions for AS Path Filters
The format of an AS path filter is ip as-path access-list list_number permit regular_expression or ip as-path access-list list_number deny regular_expression The AS path filter can be used to filter incoming or outgoing routes based on AS path information. An AS path filter can also be used in a route map to selectively modify BGP attributes based on the prefix's AS path. |
< Free Open Study > |