How to get rid of all comments in code?

Today we will talk about comments. They are very important during development process but often after finishing project and switching into production mode we don’t need them. Anyway, if you don’t want to see comments in your code anymore here is quick solution.

To delete all comments inside file just open in any IDE or advanced text editor which support “Find and Replace” function with regex.

For example, I’m using Jetbrain's IntelliJ IDEA and here  is how to do it:

  • Open Edit->Find->Replace
  • Check Regex option
  • Then find following expression inside file. It will select absolutely all kinds of comments

(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)|(<!--[\s\S]*?-->)

  • Replace it with "" (empty string)
  • Voila!

Now you have clean code, without comments!

Tural Aliyev

I'm traveloholic, musicphile, technoholic, cinephile, workaholic software developer

Istanbul http://tural.us

Subscribe to Tural's Notebook

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!