#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "//.*|/\*[\s\S]*?\*/|("(\\.|[^"])*")"
Local $sString = "#include <stdio.h>" & @CRLF & _
"" & @CRLF & _
"int main(int argc, char** argv)" & @CRLF & _
"{" & @CRLF & _
" // this comment will be removed" & @CRLF & _
" if (argc > 1) {" & @CRLF & _
" printf("Too many arguments.\n"); // this too will be removed" & @CRLF & _
" return 1;" & @CRLF & _
" }" & @CRLF & _
" printf("Please vist http://this.will.not.be.removed.com\n");" & @CRLF & _
" printf("/* This will stay */\n");" & @CRLF & _
" printf("\"/* This will stay too */\"\n");" & @CRLF & _
" return 0;" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"/*" & @CRLF & _
" this shall disappear" & @CRLF & _
"*/" & @CRLF & _
"#include <string>" & @CRLF & _
"int main(int argc, char** argv)" & @CRLF & _
"{" & @CRLF & _
" string foo = ""/*remove that!**/;" & @CRLF & _
" // Remove /* this" & @CRLF & _
" int butNotThis = 42;" & @CRLF & _
" // But do */ remove this" & @CRLF & _
" int bar = 4 /*remove this*/* 3; // but don't remove that 3. */" & @CRLF & _
" return 0;//just a comment" & @CRLF & _
"}/*end of the file has been reached.*/"
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