Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何修复从删除条件注释中删除HTML注释的正则表达式?_C#_Regex - Fatal编程技术网

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-->