#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^"*([^\s"]+@[^\s"]+)"* +<(?!\1>)[^>]*>$"
Local $sString = "##THESE SHOULD NOT MATCH" & @CRLF & _
"###PART BEFORE THE LAST < DOSE NOT CONTAIN @" & @CRLF & _
"this example <this@example.com>" & @CRLF & _
""this example" <this@example.com>" & @CRLF & _
"Name <this@example.com>" & @CRLF & _
""Name" <this@example.com>" & @CRLF & _
"this@example.com" & @CRLF & _
" <this@example.com>" & @CRLF & _
"" & @CRLF & _
"##THESE SHOULD NOT MATCH" & @CRLF & _
"###PART BEFORE THE LAST < CONTAINS @, HOWEVER BOTH STRINGS ARE IDENTICAL" & @CRLF & _
""this@example.tld" <this@example.tld>" & @CRLF & _
"this@example.tld <this@example.tld>" & @CRLF & _
"" & @CRLF & _
"##THESE SHOULD NOT MATCH" & @CRLF & _
"###PART BEFORE THE LAST < CONTAINS SPACE" & @CRLF & _
""random @ other.com" <this@example.tld>" & @CRLF & _
"random @ other.com <this@example.tld>" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"#THESE SHOULD MATCH" & @CRLF & _
"alpha@example.com <beta@example.com>" & @CRLF & _
""alpha@example.com" <beta@example.net>" & @CRLF & _
"alpha@other.tld <beta@example.com>" & @CRLF & _
""alpha@other.tld" <alpha@example.com>" & @CRLF & _
"prefix@example.edu <prefix@example.edu.com>" & @CRLF & _
""prefix@example.edu" <prefix@example.edu.com>" & @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