#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?:\/\/(?:\\\n|[^\n])*\n)|(?:\/\*[\s\S]*?\*\/)|((?:R"([^(\\\s]{0,16})\([^)]*\)\2")|(?:@"[^"]*?")|(?:"(?:\?\?'|\\\\|\\"|\\\n|[^"])*?")|(?:'(?:\\\\|\\'|\\\n|[^'])*?'))"
Local $sString = "// /*" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"/*" & @CRLF & _
" This is a multi line comment" & @CRLF & _
"" & @CRLF & _
"// <- ignored since in a comment */" & @CRLF & _
"" & @CRLF & _
"// "abc" word "" & @CRLF & _
"" & @CRLF & _
"// This is a single line comment" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"char cha1[] = "This is a string containing a combination //"," & @CRLF & _
" cha2[] = "This has /* a fake comment */ in it"," & @CRLF & _
" cha3[] = "This is tough because of (ignore this //) \" & @CRLF & _
"line continueation"," & @CRLF & _
" cha4[] = "Handle comments in strings with \" escaped quotes\" & @CRLF & _
"and escaped escaped escapes \\";" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"// This is a single line comment \" & @CRLF & _
"continuing on the next line" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"void main()" & @CRLF & _
"{" & @CRLF & _
" int chInt = '\\b\'';" & @CRLF & _
"" & @CRLF & _
" printf("Hello world!");" & @CRLF & _
"" & @CRLF & _
" cpp11_1(R"xy("/**/)xy");" & @CRLF & _
" cpp11_2(R"("/**/)");" & @CRLF & _
" cS(@"End at the right place\" /*and ignore this */);" & @CRLF & _
"" & @CRLF & _
" return 0;" & @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