#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^[^\W_]+(?:[-_.][^\W_]+){0,3}$"
Local $sString = "exampletag" & @CRLF & _
"example-tag" & @CRLF & _
"ex-ample-tag" & @CRLF & _
"ex_ample_tag" & @CRLF & _
"ex-ample_tag" & @CRLF & _
"ex.am-ple_tag" & @CRLF & _
"Ex.4m-p1e_t4g" & @CRLF & _
"" & @CRLF & _
"ex-am-pl-et-ag" & @CRLF & _
" // and variations where there's more than 3 `-` `_` or `.`" & @CRLF & _
"-exampletag" & @CRLF & _
" // no starting symbols" & @CRLF & _
"exampletag-" & @CRLF & _
" // no trailing symbols"
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