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,591
  • 7
  • 30
  • 47
angry kiwi
  • 9,824
  • 23
  • 98
  • 151

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
  • 713,503
  • 59
  • 514
  • 593