#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?x)(?| " & @CRLF & _
" \G(?!\A) # contiguous to the precedent match (inside a comment)" & @CRLF & _
" " & @CRLF & _
" (?|" & @CRLF & _
" -{2,}+([^->][^-]*) # duplicate hyphens, not part of the closing sequence" & @CRLF & _
" |" & @CRLF & _
" (-[^-]+) # preserve isolated hyphens " & @CRLF & _
" |" & @CRLF & _
" -+ (?=-->) # hyphens before closing sequence, break the contiguity" & @CRLF & _
" |" & @CRLF & _
" -->[^<]* (*SKIP)(*FAIL) # closing sequence, go to next <, break contiguity" & @CRLF & _
" )" & @CRLF & _
" |" & @CRLF & _
" [^<]*<+ # reach the next < (outside comment)" & @CRLF & _
" (?> [^<]+ <+ )*? # all characters until <!-- (include)" & @CRLF & _
" (?: !-- \K | [^<]*\z\K (*ACCEPT) ) # new comment or end of the string" & @CRLF & _
" (?|" & @CRLF & _
" -*+ ([^->][^-]*) # possible hyphens not followed by >" & @CRLF & _
" |" & @CRLF & _
" -+ (?=-->) # hyphens before closing sequence, break the contiguity" & @CRLF & _
" |" & @CRLF & _
" -?+ ([^-]+) # one hyphen followed by >" & @CRLF & _
" |" & @CRLF & _
" -->[^<]* (*SKIP)(*FAIL) () # closing sequence, go to next <, break contiguity" & @CRLF & _
" ) # () avoids a misterious bug in regex101, you can remove it" & @CRLF & _
")" & @CRLF & _
""
Local $sString = "<!----------------- toto -->" & @CRLF & _
"<!-- toto ---------------------------->" & @CRLF & _
"<!---->" & @CRLF & _
"<!----->" & @CRLF & _
"<!--->>>>--->" & @CRLF & _
"asdsd sadasdsad sadasd asdasd asdasd --> asd asdasd" & @CRLF & _
"<!--- ->>>>>>" & @CRLF & _
" ---------------------------------------" & @CRLF & _
" ***************************************" & @CRLF & _
" AUGMENTATION BLUEPRINTS" & @CRLF & _
" ***************************************" & @CRLF & _
" ---------------------------------------" & @CRLF & _
"--->----" & @CRLF & _
"<!-- toto-toto -->" & @CRLF & _
"<!--OTHER IDEAS -- " & @CRLF & _
"<anytaghere>" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"<!----PROBABLY NOT:---" & @CRLF & _
"" & @CRLF & _
"<whatever>" & @CRLF & _
"" & @CRLF & _
" --><!--"
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