#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?i)(<.+?)(?<=\s)on[a-z]+\s*=\s*(?:(['"])(?!\2).+?\2|(?:\S+?\(.*?\)(?=[\s>])))(.*?>)"
Local $sString = "<meta name="keywords" content="keyword1, keyword2, keyword3">" & @CRLF & _
"<a href="something" onclick= "bad()">text</a> onclick not in tags" & @CRLF & _
"<a href="something" onclick =bad()>text</a>" & @CRLF & _
"<a href="something" onclick=bad('test')>text</a>" & @CRLF & _
"<a href="something" onclick=bad("test")>text</a>" & @CRLF & _
"<a href="something" onclick="bad()" >text</a>" & @CRLF & _
"<a href="http://mydomain.com/index.php?oninaval=12" class="titi">text</a>" & @CRLF & _
"What if I write john+onelia=love forever?" & @CRLF & _
"" & @CRLF & _
" <a href="something" onclick="bad()">text</a> onclick not in tags " & @CRLF & _
" <a href="something" onclick=bad()>text</a>" & @CRLF & _
" <a href="something" onclick="bad()" >text</a>" & @CRLF & _
"" & @CRLF & _
"<a href="something" onclick=a++ >text</a>" & @CRLF & _
"" & @CRLF & _
"onclick="asd <span class="myclass"> not in tag too.</span>" & @CRLF & _
"<!-- onclick=" --><a href="something" onclick= "bad()">text</a>" & @CRLF & _
"<textarea><enter onclick="dothat()" text here></textarea>" & @CRLF & _
"yoko ono="john lennon"" & @CRLF & _
"<img src="/images/img1.jpg" alt="onclick=thegood() onclick=thebad() "/>" & @CRLF & _
"<img alt="onclick=" src=/images/theugly.jpg> the most important part of the message <p class="disappears"></p>" & @CRLF & _
"" & @CRLF & _
"<a href="" onmouseover=a=7>button1</a>" & @CRLF & _
"<a href="something" onclick=a++>text</a>" & @CRLF & _
"<a href="something" onclick=a<<1>text</a>" & @CRLF & _
"<a href="" onmouseover="alert(a);">button2</a>"
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