4

I am trying to cleanup my CSS documents to remove only those vendor-prefixed lines:

-webkit-......;
-o-.....;
-ms-......;
-khtml-......;
-moz-......;

As you see all lines have the same patterns ended with semi-colons, only different vendors. So far I tried with searching one by one, but there should a better way to achieve this:

preg_match("/(-webkit.*;)/", $css, $webkit);
$css = str_replace($webkit[1], '', $css);
// ... etc

Any hint would be very much appreciated. Thanks

UPDATE: The reason is I will use http://leaverou.github.com/prefixfree/, but I need a way to toggle the states for certain phase of developments, like when JS disabled.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
swan
  • 2,509
  • 3
  • 24
  • 40
  • why you want to remove it? those prefixes make sure that you get the correct result for target browser .. – Gntem Sep 12 '12 at 05:49
  • there is javascript function prefixfree that I want to use, instead. Thanks – swan Sep 12 '12 at 05:51

2 Answers2

3

Try this (-webkit-.*?;)|(-khtml-.*?;)|(-ms-.*?;)|(-moz-.*?;)|(-o-.*?;)

preg_match("/(-webkit-.*?;)|(-khtml-.*?;)|(-ms-.*?;)|(-moz-.*?;)|(-o-.*?;)/", $css, $webkit);
Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
3

try this regex /^-.*;?/m matches every line that starts with -, and possible have a ; at the end
updated
/^(\s|\t)*-.*;?/m match anything that starts with no or more whitespace or tab, has - after whitespace or tab and ends with at exactly one ;

Gntem
  • 6,949
  • 2
  • 35
  • 48