#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?s)\s*\[[^\[\]]*\](?:(?:(?!\[[^\[\]]*\]).)+\[[^\[\]]*\])*\s*"
Local $sString = "$ cat smb" & @CRLF & _
"Hi this is my config file." & @CRLF & _
"Please dont delete it" & @CRLF & _
"" & @CRLF & _
"[homes]" & @CRLF & _
" browseable = No" & @CRLF & _
" comment = Your Home" & @CRLF & _
" create mode = 0640" & @CRLF & _
" csc policy = disable" & @CRLF & _
" directory mask = 0750" & @CRLF & _
" public = No" & @CRLF & _
" writeable = Yes" & @CRLF & _
"" & @CRLF & _
"[proj]" & @CRLF & _
" browseable = Yes" & @CRLF & _
" comment = Project directories" & @CRLF & _
" csc policy = disable" & @CRLF & _
" path = /proj" & @CRLF & _
" public = No" & @CRLF & _
" writeable = Yes" & @CRLF & _
"" & @CRLF & _
" []" & @CRLF & _
"" & @CRLF & _
"This last second line." & @CRLF & _
"End of the line."
Local $sSubst = "\n"
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