Regular expression pattern matching examples
NCM uses the Microsoft .NET RegEx engine to evaluate regular expressions. For detailed information about the syntax, see Microsoft's Regular Expression Language Quick Reference. You can use regular expressions when you define policy rules and when you exclude config content from comparison.
The following examples illustrate some of the uses of Regular Expression patterns in NCM:
snmp-server community public
Finds any line that includes the text snmp-server community public
. There can be text before and/or after the string on the same line.
service tcp-keepalives-in.*\n(.*\n)*.*service tcp-keepalives-out
Finds the first line service tcp-keepalives-in
and then looks for service tcp-keepalives-out
on any line after that. The regular expression string .*\n(.*\n)*.*
is used to search any number of lines between strings.
access-list 105 deny.*tcp any any eq 139 log
Finds the line with access-list 105 deny
, followed by any number of characters of any type, followed by tcp any any eq 139 log
on the same line. The regular expression string .*
finds any character, and any number of characters on the same line. So, this could be used to find spaces, tabs, numbers, letters, or special characters.
ntp clock-period \d*
Finds any line that includes ntp clock-period
followed by any number. The regular expression string \d*
will find any number at any length, such as 3
, 48
, or 2394887
.
user \x2a
Finds any line that includes user *
. The regular expression string \x
followed by a hexadecimal value specifies an individual character. In this example, \x2a
represents the asterisk character, which has a hexadecimal value of 2a
.
\baccess-list\b.*\bjoe\b
Finds any line that includes access-list
and joe
. The regular expression \b
specifies a word boundary, so the pattern will not find (for example) access-lists
or joel
. The .
matches any character except line breaks, and the *
matches 0 or more of the preceding character. Together, the .*
allow any number of characters between the two strings, but not line breaks.