Created
July 10, 2012 18:26
-
-
Save apolaskey/3085331 to your computer and use it in GitHub Desktop.
Regex to Remove HTML Tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If accept "i",
"iframe" didnt remove