#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^(?!.*?_.*?)(?!(?:[\w]+?\.)?\-[\w\.\-]*?)(?![\w]+?\-\.(?:[\w\.\-]+?))(?=[\w])(?=[\w\.\-]*?\.+[\w\.\-]*?)(?![\w\.\-]{254})(?!(?:\.?[\w\-\.]*?[\w\-]{64,}\.)+?)[\w\.\-]+?(?<![\w\-\.]*?\.[\d]+?)(?<=[\w\-]{2,})(?<![\w\-]{25})$"
Local $sString = "# TEST" & @CRLF & _
"" & @CRLF & _
"## List of valid domains:" & @CRLF & _
"www.google.com" & @CRLF & _
"google.com" & @CRLF & _
"mkyong123.com" & @CRLF & _
"mkyong-info.com" & @CRLF & _
"sub.mkyong.com" & @CRLF & _
"sub.mkyong-info.com" & @CRLF & _
"mkyong.com.au" & @CRLF & _
"g.co" & @CRLF & _
"a.12E" & @CRLF & _
"mkyong.t.t.co" & @CRLF & _
"xn--stackoverflow.com" & @CRLF & _
"stackoverflow.xn--com" & @CRLF & _
"xn--d1ai6ai.xn--p1ai" & @CRLF & _
"stackoverflow.co.uk" & @CRLF & _
"a.xn--wgbh1c" & @CRLF & _
"1.2.3.4.com" & @CRLF & _
"x.XN--VERMGENSBERATUNG-PWB" & @CRLF & _
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com" & @CRLF & _
"www.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com" & @CRLF & _
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcde.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com" & @CRLF & _
"" & @CRLF & _
"## List of invalid domains:" & @CRLF & _
"http://google.com" & @CRLF & _
"http://www.google.com" & @CRLF & _
"dot." & @CRLF & _
"space com" & @CRLF & _
"under_score.com" & @CRLF & _
"underscore.c_om" & @CRLF & _
"-dash.com" & @CRLF & _
"dash-.com" & @CRLF & _
"sub.-dash.com" & @CRLF & _
"sub-.dash.com" & @CRLF & _
"-.com" & @CRLF & _
"-com" & @CRLF & _
".com" & @CRLF & _
"com" & @CRLF & _
"mx.gmail.com." & @CRLF & _
"mkyong.t.t.c" & @CRLF & _
"mkyong,com" & @CRLF & _
"mkyong.com/users" & @CRLF & _
"a.123" & @CRLF & _
"x.XN--VERMGENSBERATUNG-PWBB" & @CRLF & _
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkk.com" & @CRLF & _
"www.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkk.co.uk" & @CRLF & _
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcde.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.comm" & @CRLF & _
"0123456789 +-.,!@#$%^&*();\\/|<>\"\'" & @CRLF & _
"12345 -98.7 3.141 .6180 9,000 +42" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"HELP" & @CRLF & _
"" & @CRLF & _
"https://github.com/c-hive/guides/blob/57cbbf72f1152214a160f9be8a57e2c4dc868cfd/etc/regex.md#domains" & @CRLF & _
"# allowed chars" & @CRLF & _
"[\w\d\.\-]" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"EXPLAIN" & @CRLF & _
"" & @CRLF & _
"# once upon a time..." & @CRLF & _
"^" & @CRLF & _
"# doesn't contain underscore (this is so that we can use \w alter on)" & @CRLF & _
"(?![\w\d\.\-]*?_[\w\d\.\-]*?)" & @CRLF & _
"# doesn't contain dash at the beginning of a label" & @CRLF & _
"(?!(?:[\d\w]+?\.)?\-[\w\d\.\-]*?)" & @CRLF & _
"# doesn't contain dash at the end of a label" & @CRLF & _
"(?![\w\d]+?\-\.(?:[\d\w\.\-]+?))" & @CRLF & _
"# starts with a non-limit char" & @CRLF & _
"(?=[\w\d\])" & @CRLF & _
"# contains at least 1 dot" & @CRLF & _
"(?=[\w\d\.\-]*?\.+[\w\d\.\-]*?)" & @CRLF & _
"# not longer than 253 chars" & @CRLF & _
"(?![\w\d\.\-]{253})" & @CRLF & _
"# doesn't contain a label longer than 63 char" & @CRLF & _
"(?!(?:\.?[\w\d\-\.]*?[\w\d\-]{64,}\.)+?)" & @CRLF & _
"# allowed chars" & @CRLF & _
"[\w\d\.\-]+?" & @CRLF & _
"# TLD is not digit-only" & @CRLF & _
"(?<![\w\d\-\.]*?\.[\d]+?)" & @CRLF & _
"# TLD is at least 2 characters" & @CRLF & _
"(?<=[\w\d\-]{2,})" & @CRLF & _
"# TLD is at most 24 characters" & @CRLF & _
"(?<![\w\d\-]{25})" & @CRLF & _
"# the end" & @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