Remove Html Comments from a HTML doucment using Regex
March 24, 2009 at 3:56 PM
—
kevinbosch
If you ever wanted to strip the html comments out of a HTML page here is a function that does just that:
public static string RemoveHtmlComments(string input)
{
if (!string.IsNullOrEmpty(input))
{
// using a non greedy regex to get all the html or xml style comments out of the text
Regex htmlCommentStripper = new Regex("().)*-->)", RegexOptions.Singleline);
return htmlCommentStripper.Replace(input, string.Empty);
}
else
{
// the string is null or is empty so just return the string as is..
return input;
}
}
Examples of usage can be found at: http://www.codeassociate.com/caapi/html/M_CA_Common_Text_HtmlHelper_RemoveHtmlComments.htm
6bcdee16-0b16-422f-b0a5-5e201f69a486|0|.0
Posted in:
Tags: