Skip to content

Instantly share code, notes, and snippets.

@apolaskey
Created July 10, 2012 18:26
Show Gist options
  • Save apolaskey/3085331 to your computer and use it in GitHub Desktop.
Save apolaskey/3085331 to your computer and use it in GitHub Desktop.
Regex to Remove HTML Tags
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
@using System.Text.RegularExpressions
@functions {
String HtmlRemover(string html)
{
//Source: http://stackoverflow.com/questions/307013/how-do-i-filter-all-html-tags-except-a-certain-whitelist
string acceptable = "p|a"; //Tags that are a-okay to display
string stringPattern = @"</?(?(?=" + acceptable + @")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:(["",']?).*?\1?)?)*\s*/?>";
string replacement = Regex.Replace(html, stringPattern, "");
return replacement;
}
}
@gggglglglg
Copy link

If accept "i",
"iframe" didnt remove

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment