#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?ms)From:\s+(?<from>.*?)\s+To:\s+(?<to>.*?)\s+Subject:\s+(?<subject>.*?)(?:\s+References: (?<ref>.*?))?$"
Local $sString = "Text of variable length spread across several lines Serialization-type text separated by colons (eg ABC:DEF:GHI) A date" & @CRLF & _
"" & @CRLF & _
"From: One line of text To: One or more lines Subject: One or more lines References: One or more lines" & @CRLF & _
"" & @CRLF & _
"From: One line of text To: One " & @CRLF & _
"or " & @CRLF & _
"more " & @CRLF & _
"lines Subject: One or more lines References: One or more lines" & @CRLF & _
"" & @CRLF & _
"From: One line of text To: One or more lines Subject: No references." & @CRLF & _
"" & @CRLF & _
"From: One line of text To: One or more lines Subject: One " & @CRLF & _
"or " & @CRLF & _
"more " & @CRLF & _
"lines " & @CRLF & _
"References: One or more lines" & @CRLF & _
"" & @CRLF & _
"Paragraph 1 Title: A paragraph" & @CRLF & _
"" & @CRLF & _
"Paragraph 2 Title: Another paragraph"
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