#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^(([A-Za-z\d]+[\-_])*[A-Za-z\d]{2,}\.)*(?:testnet|near)$"
Local $sString = "// VALID" & @CRLF & _
"example.near" & @CRLF & _
"example.testnet" & @CRLF & _
"sub.xtrtarstsrt3322.testnet" & @CRLF & _
"1sub.sub.near" & @CRLF & _
"12.near" & @CRLF & _
"aa.testnet" & @CRLF & _
"1a.a3a.near" & @CRLF & _
"deltron-me.testnet" & @CRLF & _
"deltron_yes.near" & @CRLF & _
"// INVALID because of the capital letter but we can lowercase it on db" & @CRLF & _
"Fmish.testnet" & @CRLF & _
"" & @CRLF & _
"// INVALID" & @CRLF & _
"aa.setetstestnet" & @CRLF & _
"" & @CRLF & _
"_sentaent.testnet" & @CRLF & _
"-howabout.this.near" & @CRLF & _
"space should fail.testnet" & @CRLF & _
"space should fail.near" & @CRLF & _
"!testnet.testnet" & @CRLF & _
"2a!.near" & @CRLF & _
"n.testnet" & @CRLF & _
"shouldnotendwithperiod.testnet." & @CRLF & _
"aa.t.testnet" & @CRLF & _
"1a..near" & @CRLF & _
"touchingDotsShouldfail..testnet" & @CRLF & _
".aa.testnet"
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