#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)Diagnosis Statement:\s*.*\s*\K^([A-Z0-9]{16})$"
Local $sString = "Diagnosis Statement:" & @CRLF & _
"6/28/2011" & @CRLF & _
"RZZZCG77T77G355S" & @CRLF & _
"Report text is here ....... end of report" & @CRLF & _
"" & @CRLF & _
"Diagnosis Statement:" & @CRLF & _
"6/28/2011" & @CRLF & _
"RZZZCG77T77G355S" & @CRLF & _
"Report text is here ....... end of report" & @CRLF & _
"" & @CRLF & _
"This must not match because there is not the magic words before!" & @CRLF & _
"RZZZCG77T77G355S" & @CRLF & _
"" & @CRLF & _
"This must match, even if there is no date between the magic words and the thing to match :" & @CRLF & _
"" & @CRLF & _
"Diagnosis Statement:" & @CRLF & _
"RZZZCG77T77G355S" & @CRLF & _
"Report text is here ....... end of report"
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