#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?mi)<{1}\w+[\w\s\'\"\=]*(on[^=-\s]+)=["']([\S\w\d]*|[\S\w\d ]*)["']>{1}"
Local $sString = "<video><source onerror="alert(1)"> <img onerror="alert(shouldMatch)"> " & @CRLF & _
"" & @CRLF & _
"onerror="shouldnt match"" & @CRLF & _
"" & @CRLF & _
"<img alt="" onerror="alert(2>4)"> " & @CRLF & _
"" & @CRLF & _
"<img onerror="alert(2<4)"><img onerror="alert(2<4)">" & @CRLF & _
"" & @CRLF & _
"<img onerror="alert(!@#$%^&*() <> ""''?|\/}{][=-_)">" & @CRLF & _
"" & @CRLF & _
"<img onerror="alert()"> " & @CRLF & _
"<img onerror="(function{}())"> " & @CRLF & _
"<img onerror="">" & @CRLF & _
"" & @CRLF & _
"<img onerror="asdasdasd(){}((({}0123><456789!@#$%^&*()_+qwertyuiop[]asdfghjkl;'\/.,mnbvcxz\|ZXCVBNM<>?|":LKJHGFDSAQWERTYUIOP{}``~~">" & @CRLF & _
"" & @CRLF & _
"<asd><img onerror="(function{}())">" & @CRLF & _
"<img diabled alt="asd" onerror="(function{}())"> "
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