#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)\b(?:(?=\w{2,3}\b)(?:\d+[a-zA-Z]*|[a-zA-Z]+\d*)-){2,}(?:\d+[a-zA-Z]*|[a-zA-Z]+\d*)\b(?!-)"
Local $sString = "54-PT-001" & @CRLF & _
"54-PT-001A" & @CRLF & _
"JKS-54-002AB" & @CRLF & _
"KS-54-002B" & @CRLF & _
"JKS-64-002A" & @CRLF & _
"JKS-64-002B" & @CRLF & _
"AAA-54-002A" & @CRLF & _
"AAA-54-002" & @CRLF & _
"JKS-54-PT-002B" & @CRLF & _
"JKS-54-PT-002A" & @CRLF & _
"ABC-123-DEF-456-GHI-789" & @CRLF & _
"" & @CRLF & _
"Shoudln't match:" & @CRLF & _
"" & @CRLF & _
"only two segments:" & @CRLF & _
"JKS-54" & @CRLF & _
"" & @CRLF & _
"mix of letter-number-letter" & @CRLF & _
"A1C-PT-0000" & @CRLF & _
"" & @CRLF & _
"mix of number-letter-number" & @CRLF & _
"1A2-PT-0000" & @CRLF & _
"" & @CRLF & _
"Non-final element is longer than 3 chars:" & @CRLF & _
"FOUR-PT-0000" & @CRLF & _
"XXX-FOUR-0000" & @CRLF & _
"" & @CRLF & _
"Trailing dash" & @CRLF & _
"ABC-123-GHIJ-" & @CRLF & _
"" & @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