简体   繁体   English

匹配CSS不是评论

[英]Matching CSS which is not comment

I know there's been a lot of related questions but none seems to fill my specific needs. 我知道有很多相关问题,但似乎没有一个问题满足我的具体需求。

Basically, I need to match CSS code that is not a comment. 基本上,我需要匹配不是注释的CSS代码。
I've tried this (input first) 我试过这个(先输入)

foo FOO

(?<!/\*)foo

but it fails not to match the following: 但它无法匹配以下内容:

/* foo

and

/* comment foo

Also, (?<!/\\*\\s*)foo will cause an error. 另外, (?<!/\\*\\s*)foo会导致错误。

PS For those who may ask, I don't need to care about strings. PS对于那些可能会问的人,我不需要关心字符串。

If the CSS you are working with is "valid" and you ignore string syntax, you could use a cheap trick like this: 如果您正在使用的CSS是“有效”而您忽略字符串语法,则可以使用这样的廉价技巧:

foo(?!(?:[^/*]++|/(?!\*)|\*(?!/))*+\*/)

What it does is check that foo isn't followed by a */ (without any /* before it). 它做的是检查foo后面没有*/ (之前没有任何/* )。

(You can remove the possessive quantifiers + , if your PHP version is outdated and doesn't support them.) (如果您的PHP版本已过时且不支持,则可以删除所有格量词+ 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM