Appendix B. Regular Expressions

 <  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
Character Meaning
. Matches any single character, including white space.
* Matches zero or more sequences of the pattern.
+ Matches one or more sequences of the pattern.
? Matches zero or one occurrence of the pattern.
^ Matches the beginning of the string.
$ Matches the end of the string.
_ ( underscore ) Matches a comma (,), left brace ({), right brace (}), left parenthesis ((), right parenthesis ()), the beginning of the string, the end of the string, or a space.

Here are some examples:

  • c* matches any occurrence of the letter c in the line, including no occurrences of the letter c.

  • c+ matches one or more occurrences of the letter c in the line.

  • ca?B matches cb or caB.

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:

  • [Aa] matches either the single character A or a.

  • [1-35-7] matches a single character with the value 1, 2, 3, 5, 6, or 7.

  • ^[bB] Matches a line that begins with b or B.

  • [2-5]$ Matches a line that ends with 2, 3, 4, or 5. The caret (^) is used to reverse the meaning of the characters within the bracket .

  • [^1-3] Matches any occurrence of the characters 0 and 4 through 9.

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
Regular Expression Routes Targeted
^$ Routes originating from this AS.
^2_ All routes from a directly connected neighbor in AS 2.
^2$ Routes originated by a neighbor in AS 2.
_3_ Routes containing AS 3.
{1 2} Aggregate route using the as-set option. Routes from AS 1 and AS 2 form the aggregate.
(65530) Confederation peer. The peer is in AS 65530.

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  >  


Cisco[r] BGP-4 Command and Configuration Handbook
Cisco BGP-4 Command and Configuration Handbook
ISBN: 1587055732
EAN: 2147483647
Year: 2001
Pages: 300

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net