0

I have code like this

function get_id(){
   return 1;
   //
}

I want to remove all // inside the source code, but only those stand by it own, on a newline just like the example here. Nothing much nothing more. How can I do it?

chris85
  • 23,846
  • 7
  • 34
  • 51
angry kiwi
  • 10,730
  • 26
  • 115
  • 161

1 Answers1

2

Search using this regex:

^\s*\/\/\s*$

and replace by empty string.

If using PHP you can use \h (horizontal space) instead of \s:

$code = preg_replace('~^\h*//\h*$~m', '', $code);
anubhava
  • 761,203
  • 64
  • 569
  • 643