A regular expression is tool for mode matching. You should construct the matching mode based on certain rules, and then match the mode with the target object.
The regular expression is an expression that describes a set of strings. It consists of common characters (such as letters from "a" to "z") and particular characters (also named metacharacters). The regular expression is a template according to which you can search for the required string.
Searching for and obtaining a sub-string that matches a rule in the string.
Substituting a string according to a certain matching rule.
The regular expression consists of common characters and particular characters.
Common characters
Common characters are used to match themselves in a string, including all upper-case and lower-case letters, digits, underline, punctuations, and special symbols. For example, a matches the letter "a" in "abc", 192 matches the digit "192" in "192.168.1.1", and @ matches the symbol "@" in "xxx@xxx.com".
Particular characters
Particular characters are used together with common characters to match the complex or particular string combination. Table 1 describes particular characters and their syntax.
Particular character |
Syntax |
Example |
|---|---|---|
\ |
Defines an escape character, which is used to mark the next character (common or particular) as the common character. |
\* matches "*". |
^ |
Matches the starting position of the string. |
^10 matches "10.10.10.1" instead of "1.10.10.1". |
$ |
Matches the ending position of the string. |
1$ matches "10.10.10.1" instead of "10.10.10.2". |
* |
Matches the preceding element zero or more times. |
10* matches "1", "10", "100", and "1000". (10)* matches "null", "10", "1010", and "101010". |
+ |
Matches the preceding element one or more times. |
10+ matches "10", "100", and "1000". (10)+ matches "10", "1010", and "101010". |
? |
Matches the preceding element zero or one time. NOTE:
Huawei data communication devices do not support regular expressions
with ?. When regular expressions with ? are entered on Huawei data
communication devices, helpful information is provided. |
10? matches "1" and "10". (10)? matches "null" and "10". |
. |
Matches any single character. |
0.0 matches "0x0" and "020". .oo matches "book", "look", and "tool". |
() |
Defines a subexpression, which can be null. Both the expression and the subexpression should be matched. |
100(200)+ matches "100200" and "100200200". |
x|y |
Matches x or y. |
100|200 matches "100" or "200". 1(2|3)4 matches "124" or "134", instead of "1234", "14", "1224", and "1334". |
[xyz] |
Matches any single character in the regular expression. |
[123] matches the character 2 in "255". |
[^xyz] |
Matches any character that is not contained within the brackets. |
[^123] matches any character except for "1", "2", and "3". |
[a-z] |
Matches any character within the specified range. |
[0-9] matches any character ranging from 0 to 9. |
[^a-z] |
Matches any character beyond the specified range. |
[^0-9] matches all non-numeric characters. |
_ |
Matches a comma "," left brace "{", right brace "}", left parenthesis "(", and right parenthesis ")". Matches the starting position of the input string. Matches the ending position of the input string. Matches a space. |
_2008_ matches "2008", "space 2008 space", "space 2008", "2008 space", ",2008,", "{2008}", "(2008)", "{2008", and "(2008}". |
Unless otherwise specified, all characters in the preceding table are displayed on the screen.
Degeneration of particular characters
Certain particular characters, when being placed at the following positions in the regular expression, degenerate to common characters.
The particular characters following "\" is transferred to match particular characters themselves.
The particular characters "*", "+", and "?" placed at the starting position of the regular expression. For example, +45 matches "+45" and abc(*def) matches "abc*def".
The particular character "^" placed at any position except for the start of the regular expression. For example, abc^ matches "abc^".
The particular character "$" placed at any position except for the end of the regular expression. For example, 12$2 matches "12$2".
The right bracket such as ")" or "]" being not paired with its corresponding left bracket "(" or "[". For example, abc) matches "abc)" and 0-9] matches "0-9]".
Unless otherwise specified, degeneration rules are applicable when preceding regular expressions serve as subexpressions within parentheses.
Combination of common and particular characters
In actual application, a regular expression combines multiple common and particular characters to match certain strings.
The VRP uses a regular expression to implement the filtering function of the pipe character. A display command supports the pipe character only when there is excessive output information.
When the output information is queried according to the filtering conditions, the first line of the command output starts with the information containing the regular expression.
The command can carry the parameter | count to display the number of matching entries. The parameter | count can be used together with other parameters.
For the commands supporting regular expressions, the three filtering methods are as follows:
| begin regular-expression: displays the information that begins with the line that matches regular expression.
| exclude regular-expression: displays the information that excludes the lines that match regular expression.
| include regular-expression: displays the information that includes the lines that match regular expression.
The value of regular-expression is a string of 1 to 255 characters.
before before-line-number: displays lines that match filtering rules and the preceding before-line-number lines.
after after-line-number: displays lines that match filtering rules and the subsequent after-line-number lines.
Values of before-line-number and after-line-number are a string of 1 to 999 characters.
When a lot of information is displayed, you can specify a filtering mode in the prompt "---- More ----".
/regular-expression: displays the information that begins with the line that matches regular expression.
-regular-expression: displays the information that excludes lines that match regular expression.
+regular-expression: displays the information that includes lines that match regular expression.