Is it possible to use a Regular Expression to extract only comments from a C# file?
If so how would you do that?
Is it possible to use a Regular Expression to extract only comments from a C# file?
If so how would you do that?
Refer this: -> Finding Comments in Source Code Using Regular Expressions
after reading the article, your final RegEx would be.
(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)
FOR C#
^/[/|*](.+)$ (for single line comment )
(^\/\/.*?$|\/\*.*?\*\/) (for multilne comments)
This Regex finds all the comments in a C# file.
(((?<=//).+(?=\n))|((?<=/*)[^(\*/)]+(?=\*/)))+