#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)<section.*id="section[\d]*"[\s\S]*?<\/section>"
Local $sString = "<!DOCTYPE html>" & @CRLF & _
"<html lang="en">" & @CRLF & _
"<head>" & @CRLF & _
" <title>Whatever</title>" & @CRLF & _
"</head>" & @CRLF & _
"<body>" & @CRLF & _
" <section class="all-classes" id="section1-do-not-remove-section">" & @CRLF & _
" content2" & @CRLF & _
" content" & @CRLF & _
" </section>" & @CRLF & _
" <section class="all-classes" id="section2">" & @CRLF & _
" content" & @CRLF & _
" content2" & @CRLF & _
" </section>" & @CRLF & _
"</body>" & @CRLF & _
"<section class="all-classes" id="section3">" & @CRLF & _
" content" & @CRLF & _
" <div class="all-classes" id="section4">" & @CRLF & _
" anything" & @CRLF & _
" whatever" & @CRLF & _
" </div>" & @CRLF & _
"</section>" & @CRLF & _
"<section class="all-classes" id="section5-do-not-remove-section">" & @CRLF & _
" content" & @CRLF & _
"</section>" & @CRLF & _
"<section class="all-classes" id="section6">" & @CRLF & _
" content" & @CRLF & _
"</section>" & @CRLF & _
"<section class="all-classes" id="section7">" & @CRLF & _
" content" & @CRLF & _
"</section>" & @CRLF & _
""
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