Removing the Comments from all source code.

  • “Replace” (or “Replace in Path” if you want to remove comments in multiple files) in the regular expression mode and then use this regular expression in the “Text to find” field:
    (/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/|[ \t]*//.*)
  • and replace it with an empty string. Then press “All” to apply this replacement to the entire file or all the selected files. This will remove all block comments and line comments from your file. If you want only block comments to be removed, use this regex instead:
    (/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)
  • And if you want to just remove line comments, you can use this regex:
    ([ \t]*//.*)
 

However, I should warn that this works only %99.99 of times. You might have a string variable defined in your file like:

String myStr = "/** I am not a comment */";

This regex will turn this to:

String myStr = "";
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s