Information Technology Reference
In-Depth Information
The characters [ ] describe a range. Only one of the characters within the range is matched.
You can make the matching exclusive by using the caret (^) character at the start of the
range to exclude all the characters within the range. You can also specify a range by
providing only the beginning and the ending characters separated by a dash (-). Some
simple examples are shown in Table 4-5.
Table 4-5 Examples of Ranges
Regular Expression
Usage
[aeiouAEIOU]
Matches a, aa, Aa, eA, x2u, and so on.
[a-c1-2]$
Matches a, a1, 62, 1b, xv2, and so on.
[^act]$
Matches d, efg*, low2, actor, path, and so on, but not pact.
How to Use Regular Expressions in Cisco IOS Software
Regular expressions in IOS are only a subset of what is available from other operating
systems. The use of regular expressions within IOS can be generally described in two
categories:
Filtering the command output
Pattern matching to define policies
Regular expressions can be used in filtering outputs of show and more commands. The
entire line is treated as one string. Table 4-6 shows the three types of filtering that can be
done on an output.
Table 4-6 Regular Expressions Used to Perform Three Types of Output Filtering
Keyword
Usage
begin
Begins output lines with the first line that contains the regular
expression.
include
Displays output lines that contain the regular expression.
exclude
Displays output lines that do not contain the regular expression.
To filter the output, send the output with a pipe character (|) followed by the keyword and
a regular expression. For example, show run | begin router bgp shows the part of the
running configuration that begins with router bgp . To interrupt the filtered output, press
Ctrl-^ (press Ctrl, Shift, and 6 at the same time). Example 4-3 shows an example of filter-
ing show ip cef output to show all the prefixes associated with the interface Ethernet0/0.
Search WWH ::




Custom Search