#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?ui){\s*{\s*#\s*(?<operator>endcase|endswitch|endfor|endif|if|elif|else|for|switch|case|default)\s*(?<args>[^}]*)\s*}\s*}\s*(?<body>[^{]*(?:\s*{\s*{\s*#\s*(?!(?&operator))\s*[^}]*\s*}\s*}\s*[^{]*)*)"
Local $sString = "<div>" & @CRLF & _
"{{#if arg1.arg2}}" & @CRLF & _
"<span>{{#var arg3 static}}</span>" & @CRLF & _
"blablabla{{#for k, v in arg4}}" & @CRLF & _
"<p>{{#var k}}<span>{{#var v.arg5}}</span></p>" & @CRLF & _
"{{#if (k == "test" or v != 0) and k == 0}}" & @CRLF & _
"<span></span>" & @CRLF & _
"{{#elif k == 0}}" & @CRLF & _
"<p></p>" & @CRLF & _
"{{#else}}" & @CRLF & _
"<div></div>" & @CRLF & _
"{{#endif}}" & @CRLF & _
"{{#endfor}}" & @CRLF & _
"{{#endif}}" & @CRLF & _
"" & @CRLF & _
"{{#switch arg6}}" & @CRLF & _
"{{#case 5}}" & @CRLF & _
"case 5" & @CRLF & _
"{{#case 6, 7, 8}}" & @CRLF & _
"case 6, 7, 8" & @CRLF & _
"{{#endcase}}" & @CRLF & _
"{{#default}}" & @CRLF & _
"def" & @CRLF & _
"{{#endcase}}" & @CRLF & _
"{{#endswitch}}" & @CRLF & _
"" & @CRLF & _
"{{#for i as 0, 5}}" & @CRLF & _
"test i" & @CRLF & _
"{{#endfor}}"
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