#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?i)(?<if>#if\((?<ifContents>[^\)]+)\))(?<ifResult>[\s\S]+?)(?=#elif|#else|#end)(?<elIf>#elif[\s\S]+?(?=#else|#end))?(?<else>#else([\s\S]+?(?=#end)))?[\s\S]*?#end"
Local $sString = "NOTE: because regex doesn't support multiple captures with 1 group the 'elif' part will be parsed in part 2." & @CRLF & _
"" & @CRLF & _
"Ignore" & @CRLF & _
"" & @CRLF & _
" #if(#C.Age >= 18)" & @CRLF & _
" 18+ lesgo" & @CRLF & _
" #end" & @CRLF & _
"" & @CRLF & _
"Ignore" & @CRLF & _
"" & @CRLF & _
" #if(#C.Age >= 18)" & @CRLF & _
" 18+ lesgo" & @CRLF & _
" #else" & @CRLF & _
" No special thingy" & @CRLF & _
" #end" & @CRLF & _
"" & @CRLF & _
"Ignore" & @CRLF & _
"" & @CRLF & _
" #if(#C.Age >= 18)" & @CRLF & _
" 18+ lesgo" & @CRLF & _
" #elif(#C.Length >= 1.9m)" & @CRLF & _
" Tall boi" & @CRLF & _
" #elif(#C.Name == bob)" & @CRLF & _
" Hi bob" & @CRLF & _
" #else" & @CRLF & _
" No special thingy" & @CRLF & _
" #end" & @CRLF & _
"" & @CRLF & _
"Ignore" & @CRLF & _
"" & @CRLF & _
" #if(#C.Age >= 18)18+ lesgo #elif(#C.Length >= 1.9m)Tall boi#elif(#C.Name == bob)Hi bob #elseNo special thingy#end" & @CRLF & _
"" & @CRLF & _
"Ignore"
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