0

I want to remove HTML comments from my page, below is the format of comment

<!-- saved from url=(0116)file://D:\Documents and Settings\213039755\Local Settings\Temporary Internet Files\OLK5\abc.htm -->

I want regex for HTML comments which contains "Saved" word.

Currently I am using

Regex.Replace(content, "(?<=\\<!--\\s*save\\s*-->)", "sss");
Pramod Gupta
  • 63
  • 2
  • 11
  • Wrapping the entire regex into a `(?<= )` group won't do anything more than give you trouble. – Unihedron Jul 15 '14 at 13:12
  • Yes, [`(?<= )` is a bookbehind group, it asserts position after your match, then replaces a null position.](http://stackoverflow.com/q/22937618) See the answer below, which does what you need correctly. – Unihedron Jul 15 '14 at 13:16
  • Your second `\\s*` will match only zero-or-more whitespace, not letters etc. – Hans Kesting Jul 15 '14 at 13:18

1 Answers1

2

This should do it:

String result = Regex.Replace(content, @"<!-- saved[^>]*>", String.Empty);
Bill
  • 1,247
  • 8
  • 12