-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

5

1 Answer 1

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, "");
3
  • 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, ""); Dec 30, 2012 at 18:40
  • I tested it in Regex Hero (regexhero.net/tester) and it works fine for me. It's important that you use the option RegexOptions.SingleLine, it makes all the difference. Dec 30, 2012 at 18:42
  • No prob, I'm glad I could help :) Dec 30, 2012 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.