#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)(["'])\s*(SELECT)(?:\s+.*)?\s+(FROM)(?:\s+.*)?\1(?:[^\w]|$)"
Local $sString = " SELECT * FROM tbl -- no match - not in a string" & @CRLF & _
" "SELECT * FROM tbl" -- matches - in a double-quoted string" & @CRLF & _
" 'SELECT * FROM tbl;' -- matches - in a single-quoted string" & @CRLF & _
" 'SELECT * FROM it's -- no match - letter after end quote" & @CRLF & _
" "SELECT * FROM tbl' -- no match - quotation marks don't match" & @CRLF & _
" 'SELECT * FROM tbl" -- no match - quotation marks don't match" & @CRLF & _
" "select * from tbl" -- no match - keywords not upper case" & @CRLF & _
" 'Select * From tbl' -- no match - still not all upper case" & @CRLF & _
" "SELECT col1 FROM" -- matches - even though no table name" & @CRLF & _
" ' SELECT col1 FROM ' -- matches - as above with more whitespace" & @CRLF & _
" 'SELECT col1, col2 FROM' -- matches - with multiple columns"
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