#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?msix)<div\b # Start of outer DIV start tag." & @CRLF & _
" [^>]*? # Lazily match up to id attrib." & @CRLF & _
" \bclass\s*+=\s*+ # id attribute name and =" & @CRLF & _
" ([\'"]?+) # $1: Optional quote delimiter." & @CRLF & _
" \basd\b # specific ID to be matched." & @CRLF & _
" (?(1)\1) # If open quote, match same closing quote" & @CRLF & _
" [^>]*+> # remaining outer DIV start tag." & @CRLF & _
" ( # $2: DIV contents. (may be called recursively!)" & @CRLF & _
" (?: # Non-capture group for DIV contents alternatives." & @CRLF & _
" # DIV contents option 1: All non-DIV, non-comment stuff..." & @CRLF & _
" [^<]++ # One or more non-tag, non-comment characters." & @CRLF & _
" # DIV contents option 2: Start of a non-DIV tag..." & @CRLF & _
" | < # Match a "<", but only if it" & @CRLF & _
" (?! # is not the beginning of either" & @CRLF & _
" /?div\b # a DIV start or end tag," & @CRLF & _
" | !-- # or an HTML comment." & @CRLF & _
" ) # Ok, that < was not a DIV or comment." & @CRLF & _
" # DIV contents Option 3: an HTML comment." & @CRLF & _
" | <!--.*?--> # A non-SGML compliant HTML comment." & @CRLF & _
" # DIV contents Option 4: a nested DIV element!" & @CRLF & _
" | <div\b[^>]*+> # Inner DIV element start tag." & @CRLF & _
" (?2) # Recurse group 2 as a nested subroutine." & @CRLF & _
" </div\s*> # Inner DIV element end tag." & @CRLF & _
" )*+ # Zero or more of these contents alternatives." & @CRLF & _
" ) # End 2$: DIV contents." & @CRLF & _
" </div\s*>"
Local $sString = "<div>" & @CRLF & _
" <div class="asd">" & @CRLF & _
" <div>" & @CRLF & _
" <div>" & @CRLF & _
" Hello" & @CRLF & _
" </div>" & @CRLF & _
" </div>" & @CRLF & _
" </div>" & @CRLF & _
"</div>"
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYFULLMATCH)
; 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