using System;
using System.Text.RegularExpressions;
namespace Regex01
{
class Program
{
static string StripComments(string code)
{
var re = @"(@(?:""[^""]*"")+|""(?:[^""\n\\]+|\\.)*""|'(?:[^'\n\\]+|\\.)*')|//.*|/\*(?s:.*?)\*/";
return Regex.Replace(code, re, "$1");
}
static void Main(string[] args)
{
var input = "hello /* world */ oh \" '\\\" // ha/*i*/\" and // bai";
Console.WriteLine(input);
var noComments = StripComments(input);
Console.WriteLine(noComments);
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGV4dC5SZWd1bGFyRXhwcmVzc2lvbnM7CgpuYW1lc3BhY2UgUmVnZXgwMQp7CiAgICBjbGFzcyBQcm9ncmFtCiAgICB7CiAgICAgICAgc3RhdGljIHN0cmluZyBTdHJpcENvbW1lbnRzKHN0cmluZyBjb2RlKQogICAgICAgIHsKICAgICAgICAgICAgdmFyIHJlID0gQCIoQCg/OiIiW14iIl0qIiIpK3wiIig/OlteIiJcblxcXSt8XFwuKSoiInwnKD86W14nXG5cXF0rfFxcLikqJyl8Ly8uKnwvXCooP3M6Lio/KVwqLyI7CiAgICAgICAgICAgIHJldHVybiBSZWdleC5SZXBsYWNlKGNvZGUsIHJlLCAiJDEiKTsKICAgICAgICB9CgogICAgICAgIHN0YXRpYyB2b2lkIE1haW4oc3RyaW5nW10gYXJncykKICAgICAgICB7CiAgICAgICAgICAgIHZhciBpbnB1dCA9ICJoZWxsbyAvKiB3b3JsZCAqLyBvaCBcIiAnXFxcIiAvLyBoYS8qaSovXCIgYW5kIC8vIGJhaSI7CiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKGlucHV0KTsKCiAgICAgICAgICAgIHZhciBub0NvbW1lbnRzID0gU3RyaXBDb21tZW50cyhpbnB1dCk7CiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKG5vQ29tbWVudHMpOwogICAgICAgIH0KICAgIH0KfQo=