#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)({.*?})|#.*"
Local $sString = " This is 1. # Comment 1." & @CRLF & _
" This is 2. # Comment 2" & @CRLF & _
"" & @CRLF & _
" #Comment 3 {#Commit4}" & @CRLF & _
" This is 3." & @CRLF & _
"" & @CRLF & _
" # Commit5" & @CRLF & _
"" & @CRLF & _
" This is 4.{#This is 5} # Commit6" & @CRLF & _
"" & @CRLF & _
" #Commit7" & @CRLF & _
"" & @CRLF & _
" This is 6." & @CRLF & _
"" & @CRLF & _
" # Commit8 #Commit9" & @CRLF & _
" #Commit10" & @CRLF & _
" # Commit11" & @CRLF & _
" #Commit12 #Commit13" & @CRLF & _
" { # This is 7}; { # This is 8 } # Commit14" & @CRLF & _
" {# This is 9}; { # This is 10 }={# This is 11} {# This is 12}={# This is 13}# Commit15" & @CRLF & _
" " & @CRLF & _
" # Commit16 {# Commit17 }"
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