#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?mi)(<section[a-z="'\s]+>([\s\S]*?)<\/section>)"
Local $sString = "<chapter id="chap1">" & @CRLF & _
"<para0><title></title></para0>" & @CRLF & _
"</chapter>" & @CRLF & _
"" & @CRLF & _
"<chapter id="chap2"> <title>THEORY</title>" & @CRLF & _
"<section id="Thoery">" & @CRLF & _
"<title>theory Section</title>" & @CRLF & _
"<para0 verstatus="ver">" & @CRLF & _
"<title>Theory Para 0 </title>" & @CRLF & _
"<text>blah blah</text>" & @CRLF & _
"</para0>" & @CRLF & _
"</section>" & @CRLF & _
"" & @CRLF & _
"<section id="Next section">" & @CRLF & _
"<title>title</title>" & @CRLF & _
"<para0>" & @CRLF & _
"<title>Title</title>" & @CRLF & _
"<text>blah blah</text>" & @CRLF & _
"</para0>" & @CRLF & _
"</section>" & @CRLF & _
"" & @CRLF & _
"<section id="More sections">" & @CRLF & _
"<title>title</title>" & @CRLF & _
"<para0>" & @CRLF & _
"<title>Title</title>" & @CRLF & _
"<text>blah blah</text>" & @CRLF & _
"</para0>" & @CRLF & _
"</section>" & @CRLF & _
"" & @CRLF & _
"<section id="section">" & @CRLF & _
"<title>title</title>" & @CRLF & _
"<para0>" & @CRLF & _
"<title>Title</title>" & @CRLF & _
"<text>blah blah</text>" & @CRLF & _
"</para0>" & @CRLF & _
"</section>"
Local $sSubst = "$1"
Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst)
MsgBox($MB_SYSTEMMODAL, "Result", $sResult)
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