Find code comments using regex in an IDE

So if you are a developer,  you might need to clean up comments from a code that you might have copied from somewhere else and updating the documentation needs you to start from scracth, or you just want to get rid of comments. Afterall, it can’t be called code if can be understood. Just kidding!

For Javascript and C/C++ or PHP comments or basically any language that uses this syntax for comments

/* Your comment goes here*/

or

/**
* Your comments here
* Your comments here again
*/

the search query would be like:

/\*(.|[\r\n])*?\*/

just make sure to select regex like I did in my case in the screenshot below, so search with the following and replace with

Regex checkbox in PhpStorm IDE

Regex checkbox in PhpStorm IDE

For HTML comments, you’d use something along these lines for the regex pattern for your search and replace query


\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>

Notice: Theme without comments.php is deprecated since version 3.0.0 with no alternative available. Please include a comments.php template in your theme. in /var/www/fahdmurtaza.com/public_html/wp-includes/functions.php on line 3984

Leave a Reply

Your email address will not be published. Required fields are marked *