Regular Expression
,isco .com router(config-router)# ip as-path access list <as-acl-num> {permit | deny} <regular-expression>
router(config-router)# ip as-path access list <as-acl-num> {permit | deny} <regular-expression>
Receive routes from AS600 and directly attached AS
R1(config-router)# ip as-path access-list 1 permitA600$ R1(config-router)# ip as-path access-list 1 permitA600_[0-9]*$
Receive routes from AS600 and directly attached AS
R1(config-router)# ip as-path access-list 1 permitA600$ R1(config-router)# ip as-path access-list 1 permitA600_[0-9]*$
© 2002, Cisco Systems, Inc. All rights reserved.
Cisco CCIE Prep v1.0—Module 8-80
You can use regular expressions in the ip as-path access-list command with Border Gateway Protocol (BGP).
ip as-path access-list <as-acl-num> {permit | deny} <regular-expression>
Creating Regular Expressions
A regular expression can be a single-character pattern or a multiple-character pattern. That is, a regular expression can be a single character that matches the same single character in the input string, or multiple characters that match the same multiple characters in the input string. This section describes creating both single-character patterns and multiple-character patterns. It also discusses creating more complex regular expressions using multipliers, alternation, anchoring, and parentheses.
Single-Character Patterns
The simplest regular expression is a single character that matches itself in the input string. For example, the single-character regular expression 3 matches a corresponding 3 in the input string. You can use any letter (A-Z, a-z) or number (0-9) as a single-character pattern. The following examples are single-character regular expression patterns:
You can use a keyboard character other than a letter or a number—such as an exclamation point (!) or a tilde (~)—as a single-character pattern, but certain keyboard characters have special meaning when used in regular expressions. The following table lists the keyboard characters with special meaning.
|
Characters with Special Meaning Character |
Special Meaning |
|
|
Period |
Matches any single character, including white space |
|
|
Asterisk |
* |
Matches 0 or more sequences of the pattern |
|
Plus sign |
+ |
Matches 1 or more sequences of the pattern |
|
Question mark |
? |
Matches 0 or 1 occurrences of the pattern |
|
Caret |
A |
Matches the beginning of the input string |
|
Dollar sign |
$ |
Matches the end of the input string |
|
Underscore |
- |
Matches a comma (,), left brace ({), right brace (}), left parenthesis, right parenthesis, the beginning of the input string, the end of the input string, or a space |
|
Brackets |
[ ] |
Designates a range of single-character patterns |
|
Hyphen |
- |
Separates the end points of a range |
To use these special characters as single-character patterns, remove the special meaning by preceding each character with a backslash (\). The following examples are single-character patterns matching a dollar sign, an underscore, and a plus sign, respectively: \$
You can specify a range of single-character patterns to match against a string. For example, you can create a regular expression that matches a string containing one of the following letters: a, e, i, o, and u. Only one of these characters must exist in the string for pattern matching to succeed. To specify a range of single-character patterns, enclose the single-character patterns in square brackets ([ ]). The order of characters within the brackets is not important. For example, [aeiou] matches any one of the five vowels of the lowercase alphabet, while [abcdABCD] matches any one of the first four letters of the lowercase or uppercase alphabet.
You can simplify ranges by entering only the end points of the range, separated by a dash (-).
Simplify the previous range as follows:
To add a hyphen as a single-character pattern in your range, include another hyphen and precede it with a backslash:
You can also include a right square bracket (]) as a single-character pattern in your range. To do so, enter the following:
The previous example matches any one of the first four letters of the lowercase or uppercase alphabet, a hyphen, or a right square bracket.
You can reverse the matching of the range by including a caret (A) at the start of the range. The following example matches any letter except the ones listed:
The following example matches anything except a right square bracket (]) or the letter d:
Multiple-Character Patterns
When creating regular expressions, you can also specify a pattern containing multiple characters. You create multiple-character regular expressions by joining letters, numbers, or keyboard characters that do not have special meaning. For example, a4% is a multiple-character regular expression. Precede keyboard characters that have special meaning with a backslash (\) when you want to remove their special meaning.
With multiple-character patterns, order is important. The regular expression a4% matches the character a followed by the number 4 followed by a percent (%) sign. If the input string does not have a4% in that order, pattern matching fails. The multiple-character regular expression a. uses the special meaning of the period character (.) to match the letter a followed by any single character. With this example, the strings ab, a!, or a2 are all valid matches for the regular expression.
You can remove the special meaning of the period character by preceding it with a backslash. In the expression a\., only the string a. matches the regular expression.
Multipliers
You can create more complex regular expressions that instruct the Cisco IOS software to match multiple occurrences of a specified regular expression. To do so, you use some special characters with your single- and multiple-character patterns. The following table lists the special characters that specify "multiples" of a regular expression.
|
Special Characters Used as Multipliers Character |
Description |
|
* |
Matches 0 or more single- or multiple-character patterns |
|
+ |
Matches 1 or more single- or multiple-character patterns |
|
? |
Matches 0 or 1 occurrences of the single or multiple-character pattern |
The following example matches any number of occurrences of the letter a, including none: a*
The following pattern requires that at least one letter a be present in the string to be matched: a+
The following pattern matches the string bb or bab: ba?b
The following string matches any number of asterisks (*): \**
To use multipliers with multiple-character patterns, enclose the pattern in parentheses. In the following example, the pattern matches any number of the multiple-character string ab:
As a more complex example, the following pattern matches one or more instances of alphanumeric pairs (but not none; that is, an empty string is not a match):
The order for matches using multipliers (*, +, or ?) is longest construct first. Nested constructs are matched from outside to inside. Concatenated constructs are matched beginning at the left side of the construct. Thus, the regular expression matches A9b3, but not 9Ab3 because the letter appears first in the construct.
Continue reading here: Controlling Attributes with Route Maps
Was this article helpful?