#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?s)(?:^|\n\n)From .*?(?:\nSubject: )([^\n]*End of shift.*?\n).*?\n\n(.*?)(?=\n\nFrom |$)"
Local $sString = "From MAILER-DAEMON Fri Jul 8 12:08:34 2011" & @CRLF & _
"From: Author <author@example.com>" & @CRLF & _
"To: Recipient <recipient@example.com>" & @CRLF & _
"Subject: Sample message 1" & @CRLF & _
"" & @CRLF & _
"This is the body." & @CRLF & _
">From (should be escaped)." & @CRLF & _
"There are 3 lines." & @CRLF & _
"" & @CRLF & _
"From MAILER-DAEMON Fri Jul 8 12:08:34 2011" & @CRLF & _
"From: Author <author@example.com>" & @CRLF & _
"To: Recipient <recipient@example.com>" & @CRLF & _
"Subject: Sample message End of shift 2 " & @CRLF & _
"Other Headers: useless stuff" & @CRLF & _
"" & @CRLF & _
"This is the second body." & @CRLF & _
"" & @CRLF & _
"Stuff" & @CRLF & _
"TECH" & @CRLF & _
"" & @CRLF & _
"From MAILER-DAEMON Fri Jul 8 12:08:34 2011" & @CRLF & _
"From: Author <author@example.com>" & @CRLF & _
"To: Recipient <recipient@example.com>" & @CRLF & _
"Subject: Sample message 2" & @CRLF & _
"Precedence: bulk" & @CRLF & _
"X-No-Archive: yes" & @CRLF & _
"MIME-Version: 1.0" & @CRLF & _
"" & @CRLF & _
"This is the third body." & @CRLF & _
"" & @CRLF & _
"From MAILER-DAEMON Fri Jul 8 12:08:34 2011" & @CRLF & _
"From: Author <author@example.com>" & @CRLF & _
"To: Recipient <recipient@example.com>" & @CRLF & _
"Subject: End of shift Sample message 2" & @CRLF & _
"Precedence: bulk" & @CRLF & _
"X-No-Archive: yes" & @CRLF & _
"MIME-Version: 1.0" & @CRLF & _
"" & @CRLF & _
"This is the forth test." & @CRLF & _
"" & @CRLF & _
"This is the body." & @CRLF & _
">From (should be escaped)." & @CRLF & _
"There are 4 lights." & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"Lots of text" & @CRLF & _
"" & @CRLF & _
"TECH" & @CRLF & _
"" & @CRLF & _
"From MAILER-DAEMON Fri Jul 8 12:08:34 2011" & @CRLF & _
"From: Author <author@example.com>" & @CRLF & _
"To: Recipient <recipient@example.com>" & @CRLF & _
"Subject: Sample message 4" & @CRLF & _
"Precedence: bulk" & @CRLF & _
"X-No-Archive: yes" & @CRLF & _
"MIME-Version: 1.0" & @CRLF & _
"" & @CRLF & _
"This email is the fifth email" & @CRLF & _
"" & @CRLF & _
"TECH" & @CRLF & _
"" & @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