[Contents] [Prev] [Next] [Index] [Report an Error]

Regular Expressions

A regular expression uses special characters—often referred to as metacharacters—to define a pattern that is compared with an input string. You can use regular expressions to filter the output of show commands and to define AS-path access lists and community lists to more easily filter routes.

For examples of using regular expressions with AS-path access lists and community lists, see JUNOSe IP Services Configuration Guide.

Table 6 describes the metacharacters supported for regular expression pattern-matching.

Table 6: Supported Regular Expression Metacharacters

Metacharacter

Description

^

Matches the beginning of the input string.

Alternatively, when used as the first character within brackets—[^ ]—matches any number except the ones specified within the brackets.

$

Matches the end of the input string.

.

Matches any single character, including white space.

*

Matches 0 or more sequences of the immediately previous character or pattern.

+

Matches 1 or more sequences of the immediately previous character or pattern.

?

Matches 0 or 1 sequence of the immediately previous character or pattern.

()

Specifies patterns for multiple use when followed by one of the multiplier metacharacters: asterisk *, plus sign +, or question mark ?

[ ]

Matches any enclosed character; specifies a range of single characters.

– (hyphen)

Used within brackets to specify a range of AS or community numbers.

_ (underscore)

Matches a ^, a $, a comma, a space, a {, or a }. Placed on either side of a string to specify a literal and disallow substring matching. Numerals enclosed by underscores can be preceded or followed by any of the characters listed above.

|

Matches characters on either side of the metacharacter; logical OR.

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 E-series router, 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.


[Contents] [Prev] [Next] [Index] [Report an Error]