0

This question in not the same as asked before, becouse those patterns do not suit me and it seems they don't work correctly.

I'm trying to create regular expression that helps me to delite all comments from valid C# code. I've almost created it:

(\/\*(.|\n)*?\*\/)|(\/\/\/(.*)|\/\/(.*))

but when I meet something like this:

      /* " */ string z = /*"hello"*/"test";
      char f2 = '\"'; // symbol " for testing purposes
      Console.WriteLine("/*dfsdf*////****/**//**Hello, world!\\");/**/ //

it matches with text in string between quotes. So I need regEx that will match only c# comments but not code(like in string between quotes). I've tried to create it but in vain because my regEx knowledges are too poor.

I would be grateful for any help.

Regards Dmitry

Community
  • 1
  • 1
Dmitry Koshevoy
  • 331
  • 6
  • 16

1 Answers1

-1

Use roslyn for c# code manipulation and forgot regex. Roslyn have full access to c# code, it is what Visual Studio use behind the scene.

Aidity
  • 41
  • 10