-2

How can I remove all string like below

<!-- ebanking log on -->

second example

<!-- 

end the bottom row with 'peace of mind garuntee' 

-->

Example document : http://pastebin.com/Y4gZdceK

So it should remove all of the string blocks which starts with <!-- and ends with -->

I tried htmlagilitypack inner text but it did not remove

Charles
  • 50,943
  • 13
  • 104
  • 142
Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342

1 Answers1

2

Try this regular expression:

<!--.*?-->

Please note: You have to use RegexOptions.SingleLine to change the meaning of the dot (.) so it matches every character (instead of every character except \n).

Edit: code sample

var myRegex = new Regex(@"<!--.*?-->", RegexOptions.Singleline);
string strTargetString = @"[sample text here]";

string replacedText = myRegex.Replace(strTargetString, "");
Rui Jarimba
  • 11,166
  • 11
  • 56
  • 86
  • thanks i tried but it failed. also there are code blocks like my second example at updated first post regex = new Regex(@"", RegexOptions.Singleline); regex.Replace(srBody, ""); – Furkan Gözükara Dec 30 '12 at 18:40
  • I tested it in Regex Hero (http://regexhero.net/tester/) and it works fine for me. It's important that you use the option `RegexOptions.SingleLine`, it makes all the difference. – Rui Jarimba Dec 30 '12 at 18:42
  • No prob, I'm glad I could help :) – Rui Jarimba Dec 30 '12 at 18:52