#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)<(?:div|ul|li)(?=[^>]*\bclass="([^"]+)")(?=(?:[^>]*\bdata-\w+="([^"]+)")?)"
Local $sString = "With preg_match_all I want to get class and data-attributes in html." & @CRLF & _
"" & @CRLF & _
"I asked a similar question before. The correct answer to the previous responsibility was done with DOM. But as an alternative to the DOM structure, I also need a regex version." & @CRLF & _
"" & @CRLF & _
"The pattern works fine. However, if the lines are side-by-side, they also take class names from tags that should not be accepted." & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"<div class="noproblem"> " & @CRLF & _
" <ul class="noproblem" data-ss="1">" & @CRLF & _
" <li class="noproblem" data-ss="1">" & @CRLF & _
" <!-- <i> is not my tag. but there s no problem with that. because it s underneath . -->" & @CRLF & _
" <i class="no_problem"></i>" & @CRLF & _
" </li>" & @CRLF & _
" </ul>" & @CRLF & _
"</div>" & @CRLF & _
"" & @CRLF & _
"<div class="noproblem" data-ss="1"> <!-- problem: data-ss is not accepted -->" & @CRLF & _
" <ul class="noproblem" data-ss="1">" & @CRLF & _
" <!-- <i> is not my tag. my tags: div|ul|li . -->" & @CRLF & _
" <li class="noproblem"><i class="this_is_problem"></i>" & @CRLF & _
" </li>" & @CRLF & _
" </ul>" & @CRLF & _
"</div>" & @CRLF & _
"" & @CRLF & _
"<div class="noproblem">" & @CRLF & _
" <ul class="noproblem">" & @CRLF & _
" <!-- <i> is not my tag. my tags: div|ul|li . -->" & @CRLF & _
" <li class="noproblem"><i class="this_is_problem"></i>" & @CRLF & _
" </li>" & @CRLF & _
" <!-- <span> is not my tag. my tags: div|ul|li . -->" & @CRLF & _
" <li class="test"><span class="this_is_problem"></span></li>" & @CRLF & _
" <!-- (li class empty version): <span> is not my tag. my tags: div|ul|li . -->" & @CRLF & _
" <li><span class="this_is_problem"></span></li>" & @CRLF & _
" </ul>" & @CRLF & _
"</div>"
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