Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing Block Comments via Regex

Tags:

regex

php

I am having difficulty trying to get this regex to work. All I am trying to do is remove block comments. This is what I have so far but I can't get rid of the final */.

$string = 'this is a test /*asdfa  */ ok then';

$pattern = '/\/\*([^\*\/]*)/i';

$replacement = '';

echo preg_replace($pattern, $replacement, $string);

//this is a test */ ok then

Any help will be appreciated.

like image 475
Abs Avatar asked Nov 17 '10 17:11

Abs


1 Answers

Use a different delimiter than / -- it makes it confusing.

How about '#/\*.+?\*/#s';

like image 110
Billy ONeal Avatar answered Oct 05 '22 00:10

Billy ONeal