I’ve recently started using /*
and */
for single line comments instead of using //
. I’m still using the latter style for comments that are attached to the end of a line of code, but for lines that only have a comment on them, I’m now using the first format.
// Incorrect style
/* Correct style */
echo 'Hello World'; // correct style
Here’s a piece of Regex that can automate the process of converting these comments. You can use it in the search-and-replace functionality of your editor (texted with Sublime Text).
Find:
^([\s]*)// ([\w ]*)
Replace:
\1/* \2 */
The regex will take care not to convert //
comments that are following a line of code.