0

I am trying to remove the following part of my code:

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

I have tried the following:

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

But I am getting an error:

parsing not enough 's. regex

Hoe can I use regex to remove the block of code above?

The following code it returned for regex from this url http://creepypasta.wikia.com/wiki/She_Was_Asking_for_It

enter image description here

4334738290
  • 363
  • 1
  • 16

1 Answers1

0

@"(<!-- (.*?) -->" is missing a ). Try @"(<!-- (.*?) -->)"

That answers the failure, but your pattern is circumspect. I would use

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

Which has a look behind for <!-- and a look ahead for -->. Also set it to Multiline to span lines.

ΩmegaMan
  • 22,885
  • 8
  • 76
  • 94
  • As an addition to this answer, to the OP I'd recommend using an online tool like [Regex101](https://regex101.com/) to prototype regular expression patterns. It will help point out these kinds of simple typos. – Abion47 May 06 '17 at 20:08
  • Still not removing the code above :( – 4334738290 May 06 '17 at 20:11
  • @dontmindmeyo It would also help make sure that your pattern is working properly. If you look at [this application of your pattern](https://regex101.com/r/GNLqnL/1/), the text you provided wouldn't match as I think you intended due to the spaces you included in your pattern. – Abion47 May 06 '17 at 20:11
  • @dontmindmeyo updated for my pattern to use. Your question wasn't directly asking for a result, just how to fix the error. – ΩmegaMan May 06 '17 at 20:17