I'd like to match the 0's in this output, specifically using "Pattern Recall" feature mentioned in Cisco documentation.

The pattern is:

Gi4/3                       0             0             0             0
Gi4/4                       0             0             0             0
Gi4/5                       0             0             0             0
Gi4/6                       0             0             0             0

I'm trying to get this to work, but it gives no output:

switch#show int count | i (0 +)\\1\\2\\3\\4

According to this Cisco Doc it should work,

To create a regular expression that recalls a previous pattern, use parentheses to indicate memory of a specific pattern and a double backslash (\) followed by a digit to reuse the remembered pattern. The digit specifies the occurrence of a parenthesis in the regular expression pattern. When there is more than one remembered pattern in the regular expression, \1 indicates the first remembered pattern, \2 indicates the second remembered pattern, and so on.

2 Answers 2


There are a few things that make this fail:

  1. This is trying to match the 0 five times. The first time you write the expression it matches, then it tries to match four more times,
  2. This is matching 0 (with a trailing space) The last 0 won't have a trailing space,
  3. This expression is incrementing the remembered pattern recall number, even though you only have one pattern,
  4. The pattern recall only needs one backslash. \\1 would match the text "\1". The firstbackslash is the escape character, the character after that is the escaped character.
  5. Technically, with the trailing spaces, this would also match 10 0 0 0 but there is little chance of that being an output. There will never be a number beginning in 0 though.

So, to get the pattern you want, this will work:

#show interfaces stats  | i ( +0)\1\1\1

In this expression, you match any amount of spaces ending with a 0, repeated 3 additional times.

As a nice example of how pattern recall works. (+ 0)(+ 0)\1\2 works too. To make this more clear ( +0)( +1)\1\2\2 would match 0 1 0 1 1


The problems with your pattern matching are as follows;

  1. You don't need to escape the '\'.
  2. You are capturing only 1 group, yet referring to 4 captured groups.

You probably want something like this;

show int count | i (0 +)\1\10$

It is the same as;

0 +0 +0 +0$

I cannot use the (0 +) 3 times as \1\1\1, as we don't have any more empty space after the last $


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.