#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?mx)#Command handler" & @CRLF & _
"#===============" & @CRLF & _
"#Start of the line" & @CRLF & _
"^ #Match the command name" & @CRLF & _
"(?<cmd>[\w\d\-\_\?]+)" & @CRLF & _
"#Catch as many parameters as possible" & @CRLF & _
"(?<params>" & @CRLF & _
" (" & @CRLF & _
" \ +" & @CRLF & _
" (?<pre>[^\-\\\/\w\d\s\n\r]?)" & @CRLF & _
" [^\"]*\k<pre>" & @CRLF & _
" )*" & @CRLF & _
")?" & @CRLF & _
"#Catch as many switches as possible and save them into group" & @CRLF & _
"(?<switches>" & @CRLF & _
" (" & @CRLF & _
" \ +" & @CRLF & _
" #Switch starts with -- or - or /" & @CRLF & _
" (?:\-\-|\-|\/)" & @CRLF & _
" #Gotcha!" & @CRLF & _
" [\w\d\_]+" & @CRLF & _
" )*" & @CRLF & _
")?" & @CRLF & _
"#At the end of the line can be some spaces" & @CRLF & _
"\ *$ #End of the line"
Local $sString = "help" & @CRLF & _
"echo "lol"" & @CRLF & _
"shutdown -s /f"
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