简体   繁体   English

Dreamweaver中的正则表达式以注释CSS

[英]Regular expression in Dreamweaver to comment out css

I am trying to convert a template from responsive to non-responsive (I know, seems crazy but...) so I was told by the template developer to comment out or remove all the @media css in the file. 我试图将模板从响应模式转换为非响应模式(我知道,这似乎很疯狂,但是...),因此模板开发人员告诉我注释掉或删除文件中的所有@media CSS。 So I am looking for a regular expression that will go through a css file and find: 所以我正在寻找一个正则表达式,它将通过一个css文件并找到:

@media { some css here }} and replace it with @media {这里有一些CSS}}并替换为

/* @media { same css as above }} */ / * @media {与上述相同的CSS}} * /

I have tried variation on some examples that are similar on the webs but to no avail. 我已经尝试过对一些与网络相似但无济于事的示例进行修改。

Many thanks, Houston 非常感谢,休斯顿

This regex should do the trick: 这个正则表达式可以解决这个问题:

@media.*?{\\s*(?:.*?{.*?}\\s*)*?}

And then use the following string for the replacement: 然后使用以下字符串进行替换:

/* $0 */

Also, for this regex to work you must use the "dot matches all" option for regular expressions. 另外,为使此正则表达式正常工作,必须对正则表达式使用“点匹配所有”选项。 In most languages this is done with the /s modifier (or in something like Notepad++ there's a checkbox option that says ". matches newline"). 在大多数语言中,这是通过/s修饰符完成的(或者在类似Notepad ++的目录中,有一个复选框选项显示为“。match newline”)。

If you are using something like Notepad++ to perform the replacement, you'll want the escaped version: 如果您使用类似Notepad ++的工具来执行替换,则需要转义版本:

@media.*?{\\s*(?:.*?\\{.*?\\}\\s*)*?\\}

Regex Explanation: 正则表达式说明:

The @media.*?{ part matches up to the opening brace of the media query. @media.*?{部分与媒体查询的@media.*?{括号匹配。 Then there's \\s* to match possible white-space before the start of the inner CSS. 然后在内部CSS开始之前有\\s*来匹配可能的空格。 Next, (?:.*?{.*?}\\s*)*? 接下来, (?:.*?{.*?}\\s*)*? will match all of the inner CSS. 将匹配所有内部CSS。 Finally, the end of the media query is matched with the closing brace } . 最后,媒体查询的结尾与右括号}匹配。

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

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