#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^(?:\t| )*(?:#|%|;|//|--|REM|C|!) (?:#{64} (.*)|#{32} (.*)|#{16} (.*)|#{8} (.*)|#{4} (.*)|#{2} (.*))$"
Local $sString = "Valid comments that start with "#":" & @CRLF & _
"" & @CRLF & _
"# ################################################################ First Level" & @CRLF & _
"# ################################ Second Level" & @CRLF & _
"# ################ Third level" & @CRLF & _
"# ######## Fourth Level" & @CRLF & _
"# #### Fifth level" & @CRLF & _
"# ## Sixth level" & @CRLF & _
"" & @CRLF & _
"Valid comments that start with different characters:" & @CRLF & _
"" & @CRLF & _
"// ################################################################ 1st Level" & @CRLF & _
"; ################################ 2nd Level" & @CRLF & _
"REM ################ 3rd level" & @CRLF & _
"C ######## 4th Level" & @CRLF & _
"% #### 5th level" & @CRLF & _
"-- ## 6th level" & @CRLF & _
"" & @CRLF & _
"Valid comments that start with spaces or tabs:" & @CRLF & _
" # ################################################################ 1st level" & @CRLF & _
" ; ################################ 2nd Level" & @CRLF & _
"" & @CRLF & _
"Invalid comments:" & @CRLF & _
"" & @CRLF & _
"################################################################ No initial character" & @CRLF & _
"; ################################################ Hashes not a power of 2" & @CRLF & _
"@ ################ Character not recognized" & @CRLF & _
"C ########No space after hashes" & @CRLF & _
"% %%%%%%%% No hashes" & @CRLF & _
". # #### Period before spaces" & @CRLF & _
" ;#### No space after character"
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