#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)<<<([A-Za-z_]\w*)(?:\R(?!\1;\R).*)*\R(?:\R(?!\1;\R).*)*\R\1;\R"
Local $sString = "<<<([A-Z]+)\n.*\n\n.*\n *\1\b" & @CRLF & _
"This works if there is only one HEREDOC of that type in the file, but if there were more than one it'll look at the code between the HEREDOCs." & @CRLF & _
"" & @CRLF & _
"<<<([A-Z]+)\n(?!.*\1.*).*\n\n(?!.*\1.*).*\n *\1\b" & @CRLF & _
"With negative lookaheads should then work... but it doesn't match at all :-(" & @CRLF & _
"" & @CRLF & _
"I think I can't use negative look-behinds cause it would not contain a fixed length." & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"$out .= <<<HTML" & @CRLF & _
" aaaaa" & @CRLF & _
" aaaaa" & @CRLF & _
" bbbbb" & @CRLF & _
"HTML;" & @CRLF & _
"// Shouldn't match, cause the empty line is outside the HEREDOC" & @CRLF & _
"$out .= <<<HTML" & @CRLF & _
" aaaaa" & @CRLF & _
" aaaaa" & @CRLF & _
" bbbbb" & @CRLF & _
"HTML;" & @CRLF & _
"" & @CRLF & _
"$out .= <<<HTML" & @CRLF & _
" Should match, cause it has a empty line in the HEREDOC" & @CRLF & _
" aaaaa" & @CRLF & _
"" & @CRLF & _
" bbbbb" & @CRLF & _
"HTML;" & @CRLF & _
""
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