#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^C[AFGJKL](?! ?\d{7}) ?\d+(?:[ -]\d+)?$"
Local $sString = "CA 123456" & @CRLF & _
"CF 1" & @CRLF & _
"CK 0467 21" & @CRLF & _
"CL 4 2" & @CRLF & _
"CG 456-789" & @CRLF & _
"CJ 1-23" & @CRLF & _
"" & @CRLF & _
"And, if possible (optional), it should also match:" & @CRLF & _
"" & @CRLF & _
"CA546" & @CRLF & _
"CJ99-0" & @CRLF & _
"CK8 0565" & @CRLF & _
"" & @CRLF & _
"It should NOT match:" & @CRLF & _
"" & @CRLF & _
"CZ 123456" & @CRLF & _
"C 987-123" & @CRLF & _
"CA 12345-" & @CRLF & _
"CK 12" & @CRLF & _
"CJ -456" & @CRLF & _
"CL-654" & @CRLF & _
"CJ 1234567"
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