本文介绍了PHP Regex用于删除特定CSS注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用下面的php匹配条件编写正则表达式:

   /*
    Remove this comment line 1
    Remove this comment line 2
   */
   .class1
   {
      background:#CCC url(images/bg.png);
   }

   .class2
   {
      color: #FFF;
      background:#666 url(images/bg.png); /* DON'T remove this comment */
   }

   /* Remove this comment */
   .class3
   {
      margin:2px;
      color:#999;
      background:#FFF; /* DON'T Remove this comment */
   }

    ...etc
    ...etc

请任何人给我一个用php编写的正则表达式。谢谢。

推荐答案

如果规则是您要删除该行上没有其他代码的所有注释,则应该执行以下操作:

/^(s*/*.*?*/s*)$/m

‘m’选项使^和$匹配一行的开头和结尾。是否希望注释运行多行?

编辑:

我确信这符合要求:

/(^|
)s*/*.*?*/s*/s

您了解它在做什么吗?

这篇关于PHP Regex用于删除特定CSS注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 13:10
查看更多