#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^\d+-[[:alnum:]]+-[[:alnum:]]+_[[:alnum:]]{3}_[[:alnum:]]{3,17}_[[:alnum:]]{3,17}(_[[:alnum:]\s]{3,20})?(_[[:alnum:]\s]{3,50})?$"
Local $sString = "12345-XX-XXXXXXXX_two_three_four_fi" & @CRLF & _
"12345-XX-XXXXXXXX_two_three_four" & @CRLF & _
"12345-XX-XXXXXXXX_two_three_fourtooloooooooong" & @CRLF & _
"12345-XX-XXXXXXXX_two_three_four_five" & @CRLF & _
"12345-XX-XXXXXXXX_two_three_four_five_six" & @CRLF & _
"12345-XX-XXXXXXXX_two_three_four_value five" & @CRLF & _
"12345-XX-XXXXXXXX_two_three_four_value five_value six" & @CRLF & _
"" & @CRLF & _
"12345-XX-XXXXXXXX_two_three_four_512345678901234567890_six" & @CRLF & _
"12345-XX-XXXXXXXX_two_three_four_five_612345678901234567890123456789012345678901234567890" & @CRLF & _
"3-Abc-Def_Va2_ValueNumber3_ValueNumber4_ValueNumber5_ValueNumber6" & @CRLF & _
"mary had a little lamb 12345-XX-XXXXXXXX_two_three_four and it was delicious"
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