C# 如何修复从删除条件注释中删除HTML注释的正则表达式?
我有以下代码:C# 如何修复从删除条件注释中删除HTML注释的正则表达式?,c#,regex,C#,Regex,我有以下代码: source = Regex.Replace(source, "<!--.*?-->", string.Empty, RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled); source=Regex.Replace(source,”,string.Empty,RegexOptions.Singleline | RegexOptions.IgnoreCase | Regex
source = Regex.Replace(source, "<!--.*?-->", string.Empty, RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled);
source=Regex.Replace(source,”,string.Empty,RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled);
…它工作得很好,只是它还去除了条件注释:
<!--[if IE]>???<![endif]-->
有人能告诉我如何更新正则表达式,使其不删除条件注释吗?您可以使用:
模式:
<!--(?!\[).*?(?!<\])-->
结果:
找到1个匹配项:
1. <!--Comment-->
1。
如果它遵循正则表达式的传统规则,则需要以下内容:Regex.Replace(source,”,string.Empty,RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled);例如,“忽略任何空格,如果注释开始后有[标记],则不匹配”。
<!--(?!\[).*?(?!<\])-->
1. <!--Comment-->