#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?i)^(?=^[\w.@!#$%&'*+/=?^`{|}~-]{7,254}$)(?<username>(?=^[\w.!#$%&'*+/=?^`{|}~-]{1,64}@)[\w!#$%&'*+/=?^`{|}~-]+(?:\.[\w!#$%&'*+/=?^`{|}~-]+)*)@(?<domain>(?=\b[a-z\d.-]{5,252}$)(?:[a-z\d](?:[a-z\d-]{0,61}[a-z\d])\.)+(?:(?:[a-z](?:[a-z-]{0,61}[a-z]))|(?:(?=[a-z\d-]*?[a-z])(?=[a-z\d-]*?[\d])[a-z\d](?:[a-z\d-]{0,61}[a-z\d]))))$"
Local $sString = "Add the multiline (/m) Regex option for testing or go to te Unit Tests section..." & @CRLF & _
"" & @CRLF & _
"Valid addresses:" & @CRLF & _
"" & @CRLF & _
"test@email.com" & @CRLF & _
"Test2@email.com" & @CRLF & _
"another.test@email.com" & @CRLF & _
"testwith+flag@email.com" & @CRLF & _
"withanyofthese#!%$'&+*-/=?^_.{|}~symbols@email.com" & @CRLF & _
"upto64charactersusername56789c123456789d123456789e123456789f1234@email.com" & @CRLF & _
"test@with.any.number.of.labels.separated.by.dots.email.com" & @CRLF & _
"test@even.with.digits.1234567890.email.com" & @CRLF & _
"test@and-hypens-email.com" & @CRLF & _
"t@upto252charactersdomainname89c123456789d123456789e123456789f123.butonlyupto63charactersperlabel6789j123456789k123456789l1234567.9m123456789n123456789o123456789p123456789q123456789r123456789s1.3456789t123456789u123456789v123456789w123456789x12.email.com" & @CRLF & _
"" & @CRLF & _
"Invalid adresses:" & @CRLF & _
"" & @CRLF & _
".usernamestartingwithdot@email.com" & @CRLF & _
"usernameendingwithdot.@email.com" & @CRLF & _
"havingtwo..consecutivedotsintheusername@email.com" & @CRLF & _
"test@orinthedomainname..email.com" & @CRLF & _
"test@having.all.numerical.top-level-domain.888" & @CRLF & _
"havinglessthan2characterperlabel@1.a.email.com" & @CRLF & _
"(havingothersymbolsnotlisted)@email.com" & @CRLF & _
"usingotherthanletters.digits.and-hyphens{anddots}inthedomainname@[123.45.67.89]" & @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