$re = '/GigabitEthernet1\/1\/1(?:(?!interface GigabitEthernet)[\s\S])*(vlan.*40(?:9[12]|[6-8][0-9]|5[2-9]))/m';
$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
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php