How to delete all comments in a selected code section?

Remove all spaces before the comments too.

(\t+|\s+|\r\n)((/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*))

http://blog.ostermiller.org/find-comment


Open the Document, Hit Ctrl+H or locate and Open "Quick Replace"

1 Enable Regular Expression (Alt+E)
2 In Find FieldBox, write

//.* or /*.*

3 In Replace FieldBox, keep it empty or put text of your choice.
Note: /* */ - Multilines Comment Deletion has limitaton


I believe the search & replace in VS allows for regular expressions, it would be easy enough to search for "// (anything to end of line" or "/* (anything) */" and replace with "".

Since this is c++ (I think), one could write the regex so that it would not find 'escaped' comments.


1.//.*?\n
2./\*(.|\n)*?\*/
These RE will also delete multi-line comments. (Just use find and replace with Regular Expression turned on).