#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)(?sm)interface (\S*)(?:(?!^!$).)*port-security.*?!$"
Local $sString = "interface Vlan1" & @CRLF & _
" no ip address" & @CRLF & _
" shutdown" & @CRLF & _
"!" & @CRLF & _
"interface Vlan10" & @CRLF & _
" ip address 10.0.0.1 255.2555.255.0" & @CRLF & _
" no ip route-cache" & @CRLF & _
"!" & @CRLF & _
"interface Vlan20" & @CRLF & _
" no ip address" & @CRLF & _
"!" & @CRLF & _
"interface GigabitEthernet1/0/5" & @CRLF & _
" description PC-05" & @CRLF & _
" switchport access vlan 20" & @CRLF & _
" switchport mode access" & @CRLF & _
" switchport nonegotiate" & @CRLF & _
" shutdown" & @CRLF & _
" spanning-tree portfast" & @CRLF & _
" spanning-tree bpduguard enable" & @CRLF & _
"!" & @CRLF & _
"interface GigabitEthernet1/0/6" & @CRLF & _
" description PC-06" & @CRLF & _
" switchport access vlan 10" & @CRLF & _
" switchport mode access" & @CRLF & _
" switchport nonegotiate" & @CRLF & _
" switchport port-security maximum 2" & @CRLF & _
" switchport port-security aging time 2" & @CRLF & _
" switchport port-security violation restrict" & @CRLF & _
" switchport port-security mac-address aaaa.aaaa.aaaa vlan access" & @CRLF & _
" switchport port-security mac-address bbbb.bbbb.bbbb vlan access" & @CRLF & _
" spanning-tree portfast" & @CRLF & _
" spanning-tree bpduguard enable" & @CRLF & _
"!" & @CRLF & _
"end"
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH)
Local $aFullArray[0]
For $i = 0 To UBound($aArray) -1
_ArrayConcatenate($aFullArray, $aArray[$i])
Next
$aArray = $aFullArray
; Present the entire match result
_ArrayDisplay($aArray, "Result")
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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm