#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?mi)(SELECT|DELETE)(?:\s*\/\*.*\*\/\s*?)*\s+FROM*\s+([^\s\/*;]+)?|(?:(?:(CREATE|ALTER|DROP)(?:(?:\s*\/\*.*\*\/\s*?)*\s+OR(?:\s*\/\*.*\*\/\s*?)*\s+(REPLACE))?)(?:\s*\/\*.*\*\/\s*?)*\s+TABLE(?:(?:\s*\/\*.*\*\/\s*?)*\s+IF(?:\s*\/\*.*\*\/\s*?)*\s+EXISTS)?|(UPDATE)|(ALTER)|(INSERT)(?:\s*\/\*.*\*\/\s*?)*\s+(?:INTO?))(?:\s*\/\*.*\*\/\s*?)*\s+([^\s\/*;]+)|(?:(REPLACE)(?:\s*\/\*.*\*\/\s*?)*\s+(?:INTO?))(?:\s*\/\*.*\*\/\s*?)*\s+([^\s\/*;]+)(?:\s*\/\*.*\*\/\s*?)*\s+([^\s\/*;]+)"
Local $sString = "DROP TABLE IF EXISTS tbl1; CREATE TABLE tbl1 ..." & @CRLF & _
"CREATE TABLE tbl1 ..." & @CRLF & _
"CREATE OR REPLACE 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 from tbl4 ..." & @CRLF & _
"select from select_table insert into table_ttt" & @CRLF & _
"alter table alter_table " & @CRLF & _
"#1 some optional statements like CREATE /*some comments*/ TABLE table_name everything else" & @CRLF & _
"#1 some optional statements like CREATE /*some comments*/ OR REPLACE TABLE table_name everything else" & @CRLF & _
"#2 some optional statements like INSERT /*some comments*/ INTO /*some comments*/ table_name" & @CRLF & _
"#3 some optional statements like 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