#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(<h([1-3]{1})[^>]*?(?! id)(?:id=\"([^\"]*)\"[^>]*)?>)(.*)<\/h\2>|<!--nextpage-->"
Local $sString = "<h1>Test</h1>" & @CRLF & _
"<h1 id="test">Test</h1>" & @CRLF & _
"<h2 test="testattr" id="id">Test</h2>" & @CRLF & _
"<h3 id="id" test="test">Test</h3>" & @CRLF & _
"<h3 test="test" id="test" test="test">TEST</h3>" & @CRLF & _
"<h4></h4>" & @CRLF & _
"test" & @CRLF & _
"sdlfkdslf" & @CRLF & _
"<table>" & @CRLF & _
"h1" & @CRLF & _
"<!--nextpage-->"
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