Regular Expressions 101

Community Patterns

How do I write a Regex to inspect Cisco Interfaces

3

Regular Expression
PCRE (PHP <7.3)

/
interface GigabitEthernet1\/(1[2-9]|[1-2][0-1]).*\n(.*\n)*.* description \*\* Unused Port \*\*.*\n(.*\n)*.* switchport access vlan 1002.*\n(.*\n)*.* switchport mode access.*\n(.*\n)*.* switchport port-security.*\n(.*\n)*.* switchport port-security mac-address sticky.*\n(.*\n)*.* shutdown.*\n(.*\n)*.* no cdp enable.*\n(.*\n)*.* spanning-tree portfast
/

Description

I am asking for help in writing a regular expression to shorten this expression. I need the string below to search every interface within the range of 1 -24 to validate the configuration. If one interface does not have the required configuration then the expression fails.

interface GigabitEthernet1/1 thru 24.\n(.\n). description ** Unused Port **.\n(.\n). switchport access vlan 333

Submitted by Pirates - 9 years ago