从css文件中删除注释

I have to read a css file and remove its commentaries, so i've decided to use the preg_replace function from php:

$original = '
/*
foo
*/
.test, input[type="text"]{ color: blue; }

/* bar */
a:hover{
text-decoration: underline;
color: red;
background: #FFF;
}';

echo preg_replace('/\/\*.*\*\//s', '', $original);

the problem is that its losing the line .test, input[type="text"]{ color: blue; }

Change .* to .*?.

echo preg_replace('#/\*.*?\*/#s', '', $original);

This will only remove /* up to the closest */ rather than the furthest.

I would approach it as follows:

\/\*((?!\*\/).*?)\*\/


\/\*            # Start-of-comment
((?!\*\/).*?)   # Any character 0 or more times, lazy,
                #   without matching an end-of-comment
\*\/            # End-of-comment

Demo