Search code examples
visual-studio-2010macroskeyboard-shortcuts

How to delete all comments in a selected code section?


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.


Solution

  • For searching and replacing code in Visual Studio - Visual Studio has a built in find and replace. Use regular expressions in Visual Studio

    The below regular expression will also remove spaces before the comments too.

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

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