2

Looking for some assistance with a regex. My skills are pretty elementary and I haven't been able to find the answer.

I'm using regex it to go though a config file, and want to confirm that interface GigabitEthernet1/1/1 is not trunking vlan 4052-4092. Since the config spans multiple lines, and there may be different config elements between the interface and trunking statements, I was trying to do it using something like this:

GigabitEthernet1\/1\/1[\s\S]*?(vlan.*40[5-8][0-9]|9[12])

This works if GigabitEthernet1/1/1 has a 40xx vlan in the allowed statement, but if doesn't, the search continues until it finds it's match on the next interface. Is there a way I can get the regex to stop looking once it hits the end of the 1/1/1 interface configuration?

interface GigabitEthernet1/1/1
 description link-to-someswitch-Gi2/0/1
 switchport access vlan 3109
 switchport trunk allowed vlan 300,301,350,358,800,3109
 switchport trunk encapsulation dot1q
 switchport trunk native vlan 3109
 switchport mode dynamic desirable
 srr-queue bandwidth share 40 20 20 20
 srr-queue bandwidth shape  10 0 0 0
 priority-queue out 
 no snmp trap link-status
 mls qos trust dscp
 spanning-tree portfast disable
!
interface GigabitEthernet1/1/2
 description link-to-someswitch2-Gi2/0/1
 switchport access vlan 3609
 switchport trunk allowed vlan 300,301,350,358,800,3609,4088
 switchport trunk encapsulation dot1q
 switchport trunk native vlan 3109
 switchport mode dynamic desirable
 srr-queue bandwidth share 40 20 20 20
 srr-queue bandwidth shape  10 0 0 0
 priority-queue out 
 no snmp trap link-status
 mls qos trust dscp
 spanning-tree portfast disable

Thanks for the help. I should mention that this inst' for application into a specific programming language, but rather going into a management system that supports regex for finding elements that a config file should or shouldn't include.

neovox
  • 23
  • 2

1 Answers1

0

Try this Regex:

GigabitEthernet1\/1\/1(?:(?!interface GigabitEthernet)[\s\S])*(vlan.*40(?:9[12]|[6-8][0-9]|5[2-9]))

Click for Demo

Explanation:

  • GigabitEthernet1\/1\/1 - matches GigabitEthernet1/1/1
  • (?:(?!interface GigabitEthernet)[\s\S])* - Tempered Greedy Token - matches 0+ occurrences of any character that does not start with the interface GigabitEthernet
  • (vlan.*40(?:9[12]|[6-8][0-9]|5[2-9])) - matches vlan followed by 0+ occurrences of any character except a new line character and finally matches the required number between 4052 to 4092
Gurmanjot Singh
  • 10,224
  • 2
  • 19
  • 43
  • Thank you. This is working. Thanks for the explanation too. I spent way longer yesterday than I care to admit trying to figure it out. – neovox Feb 01 '19 at 13:18