#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?mi)^(?:(?=.*%)(?![A-Z]{1,5}[0-9])(?:%?[A-Z]){0,6}(?:(?:%?[A-Z0-9]){1,2})?(?:(?:%?[A-Z]){1,3})?%?)$|^(?:[A-Z]{6}(?:[A-Z0-9]{2})(?:[A-Z]{3})?)$|^$"
Local $sString = "" & @CRLF & _
"-> correct: Empty string" & @CRLF & _
"AaBB%" & @CRLF & _
"ABCDE%" & @CRLF & _
"AAAAAA33" & @CRLF & _
"AABBCCXX" & @CRLF & _
"AABBCC44XXX" & @CRLF & _
" -> correct" & @CRLF & _
"AA%33" & @CRLF & _
" -> correct ( % avoid the max number)" & @CRLF & _
"%AAB%BCC4%4X%XX%" & @CRLF & _
" -> correct (because % should be ignored in length, length of alpha and alphanumeric is respected here)" & @CRLF & _
"A%3" & @CRLF & _
"AA%33%" & @CRLF & _
"%AA33%" & @CRLF & _
"%AA3%" & @CRLF & _
"%3" & @CRLF & _
" -> correct according comments" & @CRLF & _
" ----------------------------------------------" & @CRLF & _
"AABBCCXXX" & @CRLF & _
"AABBCC44XX" & @CRLF & _
" -> wrong" & @CRLF & _
"AABb" & @CRLF & _
"AAbbCC" & @CRLF & _
"ABCDEF" & @CRLF & _
" -> wrong (need exactly 6 alpha + 2 alphanumeric when there is no %)" & @CRLF & _
"AAABB3%" & @CRLF & _
" -> wrong (need exactly 6 alpha before numeric)" & @CRLF & _
"AABBCC44XXXE" & @CRLF & _
" -> wrong (length of alpha not respected)" & @CRLF & _
"%AABBCC44XXXE" & @CRLF & _
" -> wrong (length of alpha not respected)"
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