#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?i)\B@([a-z0-9](?:-(?=[a-z0-9])|[a-z0-9]){0,38}(?<=[a-z0-9]))"
Local $sString = "@username" & @CRLF & _
"" & @CRLF & _
"@user in a @user2 pagagraph of @user: text @usern-ame! @inalid- " & @CRLF & _
"" & @CRLF & _
"@d" & @CRLF & _
"" & @CRLF & _
"@12345678912345678912345678911112345678904 " & @CRLF & _
"" & @CRLF & _
"@invalid--username" & @CRLF & _
"" & @CRLF & _
"and @valid-username-: l" & @CRLF & _
"" & @CRLF & _
"@-a" & @CRLF & _
"@-invalid" & @CRLF & _
"@1" & @CRLF & _
"@a" & @CRLF & _
"" & @CRLF & _
"@invalid-" & @CRLF & _
"" & @CRLF & _
"hdj @hfd.com" & @CRLF & _
"" & @CRLF & _
"some @valid-dd username" & @CRLF & _
"" & @CRLF & _
"email@test.com " & @CRLF & _
"" & @CRLF & _
"@validu-sername- but is it worth it?" & @CRLF & _
"" & @CRLF & _
"@johndoe." & @CRLF & _
"@johndoe-" & @CRLF & _
"@johndoe-a" & @CRLF & _
"" & @CRLF & _
"@fo-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o"
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