0

I am trying to quickly remove comments from code using NotePad++ regex search function and I have got a regex for several types of comment.

(?s)/\*.*?\*/

Removes comments like /*** comment ***/ or 
/*
 * comment
 */

However when it comes to a comment such as

your code //Comment

I cannot find a regex which works.

I have tried a regex such as

//(?:[^\w]*\w){0,}(?!\n)

However it doesn't stop at the end of a line.

So my question is what regex should I use which will remove from and including // to the end of a line

ndnenkov
  • 35,425
  • 9
  • 72
  • 104
Dan
  • 7,286
  • 6
  • 49
  • 114
  • Possible duplicate of [Is there a way to delete all comments in a file using Notepad++?](http://stackoverflow.com/questions/8748313/is-there-a-way-to-delete-all-comments-in-a-file-using-notepad) – Niklas Jan 13 '16 at 10:12

1 Answers1

4
//.*$
  • // - the comment
  • .* - any amount of characters
  • $ - the end of the line

You have to be careful though. For example if there is a string containing //, it will still be considered a comment.

ndnenkov
  • 35,425
  • 9
  • 72
  • 104