How to delete all comments in a selected code section?

Viewed 40062

Every once in a while, my code gets littered with many useless comments, most of them are obsolete lines of code, and some are obsolete "memos to self".
So I was wondering if there's a way to just select a code section, and with some magic key combination or macro, delete all of those.

Thanks.

8 Answers

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

I would like to combine the two answers and write my own answer.

  1. Open the Document, Hit Ctrl+H or locate and Open "Quick Replace" (See Arpan's answer )

  2. Hit Alt+E for enable Regular Expression

  3. In Find FieldBox, write the following regular expression (See Jonmeyer's answer)

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

  4. In Replace FieldBox, keep it empty or put text of your choice.

For example:

enter image description here

Related