#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)(?:(?:CREATE(?:(?:\s*\/\*.*\*\/\s*?)*\s+OR(?:\s*\/\*.*\*\/\s*?)*\s+REPLACE)?|DROP)(?:\s*\/\*.*\*\/\s*?)*\s+TABLE(?:(?:\s*\/\*.*\*\/\s*?)*\s+IF(?:\s*\/\*.*\*\/\s*?)*\s+EXISTS)?|UPDATE|DELETE|INSERT(?:\s*\/\*.*\*\/\s*?)*\s+INTO)(?:\s*\/\*.*\*\/\s*?)*\s+([^\s\/*]+)"
Local $sString = "CREATE TABLE tbl1 ..." & @CRLF & _
"CREATE OR REPLACE TABLE tbl1 ..." & @CRLF & _
"DROP TABLE IF EXISTS tbl1; CREATE TABLE tbl1 ..." & @CRLF & _
"INSERT /*some comment*/ INTO tbl2 ..." & @CRLF & _
"INSERT /*some comment*/ INTO tbl2 ..." & @CRLF & _
"UPDATE tbl3 SET col1 = ..." & @CRLF & _
"/*some garbage comments*/ UPDATE tbl3 SET col1 = ... " & @CRLF & _
"DELETE tbl4 ..." & @CRLF & _
"#1 some optional statements like drop table CREATE /*some comments*/ TABLE table_name everything else" & @CRLF & _
"#1 some optional statements like drop table CREATE /*some comments*/ OR REPLACE TABLE table_name everything else" & @CRLF & _
"#2 some optional statements like drop table INSERT /*some comments*/ INTO /*some comments*/ table_name" & @CRLF & _
"#3 some optional statements like drop table UPDATE /*some comments*/ table_name everything else"
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