#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?xs)(?=<ul\s+id=""matchMe""\s+type=""square""\s*>) # match start with <ul id="matchMe"..." & @CRLF & _
"(?> # atomic group / don't backtrack (faster)" & @CRLF & _
" <!-- .*? --> | # match xml / html comment" & @CRLF & _
" <[^>]*/\s*> | # self closing tag" & @CRLF & _
" (?<opentag><(?!\s*/)[^>]*[^/]>) | # push opening xml tag" & @CRLF & _
" (?<-opentag><\s*/[^>]*[^/]>) | # pop closing xml tag" & @CRLF & _
" [^<>]* # something between tags" & @CRLF & _
")* # match as many xml tags as possible" & @CRLF & _
"(?(opentag)(?!)) # ensure no 'opentag' groups are on stack"
Local $sString = "<html>" & @CRLF & _
"<body>" & @CRLF & _
"<div>" & @CRLF & _
" <br />" & @CRLF & _
" <ul id="matchMe" type="square">" & @CRLF & _
" <li>stuff...</li>" & @CRLF & _
" <li>more stuff</li>" & @CRLF & _
" <li>" & @CRLF & _
" <div>" & @CRLF & _
" <p>Lorem ipsum< /p>" & @CRLF & _
" <hr class="important" / >" & @CRLF & _
" <span>still more</span>" & @CRLF & _
" <ul>" & @CRLF & _
" <li>Another >ul<, oh my!</li>" & @CRLF & _
" <li>...</li>" & @CRLF & _
" </ul>" & @CRLF & _
" </div>" & @CRLF & _
" </li>" & @CRLF & _
" </ul>" & @CRLF & _
"</div>" & @CRLF & _
"</body>" & @CRLF & _
"</html>"
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