package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)GigabitEthernet1\/1\/1(?:(?!interface GigabitEthernet)[\s\S])*(vlan.*40(?:9[12]|[6-8][0-9]|5[2-9]))`)
var str = `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
interface GigabitEthernet1/1/1
description link-to-someswitch-Gi2/0/1
switchport access vlan 3109
switchport trunk allowed vlan 300,301,350,358,800,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
`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/