fork(7) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace Regex01
  5. {
  6. class Program
  7. {
  8. static string StripComments(string code)
  9. {
  10. var re = @"(@(?:""[^""]*"")+|""(?:[^""\n\\]+|\\.)*""|'(?:[^'\n\\]+|\\.)*')|//.*|/\*(?s:.*?)\*/";
  11. return Regex.Replace(code, re, "$1");
  12. }
  13.  
  14. static void Main(string[] args)
  15. {
  16. var input = "hello /* world */ oh \" '\\\" // ha/*i*/\" and // bai";
  17. Console.WriteLine(input);
  18.  
  19. var noComments = StripComments(input);
  20. Console.WriteLine(noComments);
  21. }
  22. }
  23. }
  24.  
Success #stdin #stdout 0.08s 37424KB
stdin
Standard input is empty
stdout
hello /* world */ oh " '\" // ha/*i*/" and // bai
hello  oh " '\" // ha/*i*/" and