删除正则表达式的代码块

时间:2017-05-06 20:04:19

标签: c# regex

我正在尝试删除代码的以下部分:

<!-- 
NewPP limit report
Preprocessor node count: 1/300000
Post‐expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Expensive parser function count: 0/100
-->

<!-- Saved in parser cache with key creepypasta:pcache:idhash:29041-0!*!*!*!*!2!* -->

我尝试了以下内容:

body = Regex.Replace(body, @"(<!-- (.*?) -->", "");

但是我收到了一个错误:

  

解析不够。正则表达式

我可以使用正则表达式删除上面的代码块吗?

以下代码从此网址http://creepypasta.wikia.com/wiki/She_Was_Asking_for_It

返回正则表达式

enter image description here

1 个答案:

答案 0 :(得分:0)

@"(<!-- (.*?) -->"缺少)。试试@"(<!-- (.*?) -->)"

这回答了失败,但你的模式是谨慎的。我会用

(?<=<!--).+?(?=-->)

了解<!--并了解-->。同时将其设置为Multiline以跨越行。