Date created: Tuesday, May 21, 2013 10:07:26 AM. Last modified: Tuesday, September 12, 2017 11:29:22 AM

IOS Regex

NB: To enter a question mark ? character, use CTRL+SHIFT+V and then the question mark.

Regex Syntax (from INE)

+------------------------------------------------------+
| CHAR | USAGE                                         |
+------------------------------------------------------|
|  ^   | Start of string                               |
|------|-----------------------------------------------|
|  $   | End of string                                 |
|------|-----------------------------------------------|
|  []  | Range of characters                           |
|------|-----------------------------------------------|
|  -   | Used to specify range ( i.e. [0-9] )          |
|------|-----------------------------------------------|
|  ( ) | Logical grouping                              |
|------|-----------------------------------------------|
|  .   | Any single character                          |
|------|-----------------------------------------------|
|  *   | Zero or more instances                        |
|------|-----------------------------------------------|
|  +   | One or more instance                          |
|------|-----------------------------------------------|
|  ?   | Zero or one instance                          |
|------|-----------------------------------------------|
|  _   | Comma, open or close brace, open or close     |
|      | parentheses, start or end of string, or space |
+------------------------------------------------------+

+-------------+---------------------------+
| Expression  | Meaning                   |
|-------------+---------------------------|
| .*          | Anything                  |
|-------------+---------------------------|
| ^$          | Locally originated routes |
|-------------+---------------------------|
| ^100_       | Learned from AS 100       |
|-------------+---------------------------|
| _100$       | Originated in AS 100      |
|-------------+---------------------------|
| _100_       | Any instance of AS 100    |
|-------------+---------------------------|
| ^[0-9]+$    | Directly connected ASes   |
+-------------+---------------------------+

IOS Regex (from Cisco IOS Essentials 2.9 book):

^200$ match AS200 only
.* match anything
.+ match at least one character
^* match all ASes including local AS
^$ match this AS only
^200_ match all ASes received from AS200
_200_ match all ASes which have AS200 in the path
_200$ match all ASes with AS200 origin only, whatever the path
^200_210$ match AS210 origin and received from AS200 only
_200_210_ match all ASes which have been through AS200 fl‡ AS210 link
^(200_)+$ match at least one of AS200 (or multiple occurrences of one AS, usually from AS_PATH stuffing)

^(_[0-9]+)$ match at least one AS (or multiple occurrences of one AS)
_\(65350\)_ match all ASes which have confederation sub-AS 65350 in the path
^[0-9]+$ match AS_PATH length of one
^[0-9]+_[0-9]+$ match AS_PATH length of two
^[0-9]*_[0-9]+$ match AS_PATH length of one or two
^[0-9]*_[0-9]*$ match AS_PATH length of one or two
^[0-9]+_[0-9]+_[0-9]+$ match AS_PATH length of three
_(701|1800)_ match anything which has gone through AS701 or AS1800
_1849(_.+_)12163$ match anything of origin AS12163 and passed through AS1849

IOS Regex

Show access lists applied to interfaces

show ip interface | include line protocol|access list

 

Router Commands

Extended community lists:

ip extcommunity-list expanded eBGP-VPNv4-FILTER-EXTCOMM permit RT:65002:*

ip extcommunity-list expanded RT-Filter permit 10:[1-2]*
ip extcommunity-list 500 deny _65412_

BGP regex:

! Show paths with at least 15 AS hops in the path

show bgp vpnv4 unicast all regexp .+_.+_.+_.+_.+_.+_.+_.+_.+_.+_.+_.+_.+_.+_.+_

! Show paths that contain AS 12345 in the path (they transit AS 12345):

_12345_


! Show paths that originate from a specific AS

_12345$


! Show paths that are received from direct peer AS 12345

^12345_


! Show only local AS paths

^$


! Show directly connected AS/peer routes

^[0-9]+$

 

Switch Commands

Show unused/down interfaces:

as04#sh int counters                    

Port            InOctets    InUcastPkts    InMcastPkts    InBcastPkts 
Gi0/1       241238746846      258976893        1646800         779998 
Gi0/2        83902902665      186971249          31149         580250 
Gi0/3          983670603        1107836          58664            627 
Gi0/4                  0              0              0              0 
Gi0/5       238576004381      225394145              4            357 
Gi0/6        76762626832      203773545             16        1429506 
Gi0/7                  0              0              0              0 
.......

as04#show int counters | i _0_.*_0_.*_0_.*_0_
Gi0/4                  0              0              0              0 
Gi0/7                  0              0              0              0 
Gi0/8                  0              0              0              0 
Gi0/12                 0              0              0              0 
......

as04#sh int count | i 0 +0 + 0 +0
Gi0/4                  0              0              0              0 
Gi0/7                  0              0              0              0 
Gi0/8                  0              0              0              0 
Gi0/12                 0              0              0              0 
......

sh int | i FastEthernet|0 packets input
sh int | i GigabitEthernet|0 packets input

GigabitEthernet0/1 is up, line protocol is up (connected) 
GigabitEthernet0/2 is up, line protocol is up (connected) 
GigabitEthernet0/3 is up, line protocol is up (connected) 
GigabitEthernet0/4 is down, line protocol is down (notconnect) 
     0 packets input, 0 bytes, 0 no buffer
GigabitEthernet0/5 is up, line protocol is up (connected) 
     225550140 packets input, 238695608139 bytes, 0 no buffer
GigabitEthernet0/6 is up, line protocol is up (connected) 
GigabitEthernet0/7 is down, line protocol is down (notconnect) 
     0 packets input, 0 bytes, 0 no buffer

Show physical interfaces not sub-interfaces

! IOS-XR ASR9000

RP/0/RSP1/CPU0:pe1#show int desc | utility egrep -e "Te.*/0 |Te.*/1 |Te.*/2 |Te.*/3 "
Te0/0/0/0          up          up          Physical-to-aaa
Te0/0/0/1          up          up          Link-to-zzz:Nexus7K2:E1/7
Te0/0/0/2          up          up          Link-to-zzz:Nexus7K1:E1/7
Te0/0/0/3          up          up          Physical-to-xxxx-sw1:Eth1/48
Te0/1/0/0          up          up          Physical-to-xxx-pe2:Te0/1/0/0
Te0/1/0/1          up          up          Physical-to-yyy-SW1:Internet-Outside-VRF:CCP000113
Te0/1/0/2          up          up          Physical-to-yyy-SW1:All-VRFs:CCP000105
Te0/1/0/3          up          up          Physical-to-yyy:PWE3-105-to-CPK:CCP000115

! Improved to mix 1G and 10G interfaces

RP/0/RSP0/CPU0:abr1#show int desc | i "Te|Gi" | inc "/[0-9][0-9]? "
Gi0/0/0/0          up          up          xxxxxxx
Gi0/0/0/1          up          up          xxxxxxx
Gi0/0/0/2          up          up          xxxxxxx
...
Gi0/0/0/17         admin-down  admin-down  xxxxxxx
Gi0/0/0/18         admin-down  admin-down  xxxxxxx
Gi0/0/0/19         up          up          xxxxxxx
Te0/0/1/0          up          up          xxxxxxx
Te0/0/1/1          up          up          xxxxxxx
Te0/0/1/2          up          up          xxxxxxx
Te0/0/1/3          admin-down  admin-down  xxxxxxx
Te0/0/2/0          up          up          xxxxxxx
Te0/0/2/1          up          up          xxxxxxx
Te0/0/2/2          up          up          xxxxxxx
Te0/0/2/3          up          up          xxxxxxx

! Improved to a single statement

RP/0/RSP0/CPU0:abr1#show int desc | i "[Te|Gi].*/[0-9][0-9]? "
Gi0/0/0/0          up          up          xxxxxxx
Gi0/0/0/1          up          up          xxxxxxx
Gi0/0/0/2          up          up          xxxxxxx
...
Gi0/0/0/17         admin-down  admin-down  xxxxxxx
Gi0/0/0/18         admin-down  admin-down  xxxxxxx
Gi0/0/0/19         up          up          xxxxxxx
Te0/0/1/0          up          up          xxxxxxx
Te0/0/1/1          up          up          xxxxxxx
Te0/0/1/2          up          up          xxxxxxx
Te0/0/1/3          admin-down  admin-down  xxxxxxx
Te0/0/2/0          up          up          xxxxxxx
Te0/0/2/1          up          up          xxxxxxx
Te0/0/2/2          up          up          xxxxxxx
Te0/0/2/3          up          up          xxxxxxx

Previous page: OSPFv2 IPFRR - LFA & rLFA
Next page: DHCP Inside VRF