#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?:\/\/(?:\\\n|[^\n])*\n)|(?:\/\*(?:\n|\r|.)*?\*\/)|(("|')(?:\\\\|\\\2|\\\n|[^\2])*?\2)"
Local $sString = "// /*" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"/*" & @CRLF & _
" This is a multi line comment" & @CRLF & _
"" & @CRLF & _
"// */" & @CRLF & _
"" & @CRLF & _
"// " qwe" dsfdsf "" & @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 tuff because of (ignore this //) \" & @CRLF & _
"line continueation"," & @CRLF & _
" cha4[] = "Handle comments in strings with \" escaped quotes\" & @CRLF & _
"and escaped escaped escapes";" & @CRLF & _
"" & @CRLF & _
" char array[] = "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 & _
" printf("Hello world!");" & @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