[英]Using Regex to remove css comments
How can I remove comments from CSS using Regex.Replace()
? 如何使用
Regex.Replace()
从CSS删除注释?
Note - I'm not able to use the regex mentioned here in C# - Regular expression to remove CSS comments . 注意-我无法使用C#- 正则表达式中此处提到的正则表达式删除CSS注释 。
That would be normally enough (assuming cssLines
is a string containing all lines of your CSS file): 通常就足够了(假设
cssLines
是一个包含CSS文件所有行的字符串):
Regex.Replace(cssLines, @"/\*.+?\*/", string.Empty, RegexOptions.Singleline)
Please note that the Singleline
option will allow to match multi-line comments. 请注意,“
Singleline
选项将允许匹配多行注释。
使用链接问题中的正则表达式,如下所示:
var rx = new Regex(@"(?<!"")\/\*.+?\*\/(?!"")");
I wonder if the following version of Maxim's solution would be faster. 我想知道以下版本的Maxim解决方案是否会更快。
"/\*[^*]*.*?\*/"
As the discussion shows this will also eliminate comments within string literals. 如讨论所示,这还将消除字符串文字中的注释。
Very late reply but thought it will be useful for some 回复很晚,但认为对某些人有用
"(?:/*(.|[\\r\\n]) ?/)|(?:(?([^)])//. )" “((?:/ *(。| [\\ r \\ n]) ?/)|(?:(?([^)])//。 )”
This will help removing css comments both singleline and multiline.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.