删除除一个标记之外的所有html标记

时间:2022-12-01 00:14:00

I have some code to remove all html tag but I want to remove all html but except </td> and </tr> tags.

我有一些代码删除所有的html标签,但我想删除所有的HTML,但 和 标签除外。

How can this be done?

如何才能做到这一点?

public string HtmlStrip( string input)
{
    input = Regex.Replace(input, "<input>(.|\n)*?</input>", "*");
    input = Regex.Replace(input, @"<xml>(.|\n)*?</xml>", "*"); // remove all <xml></xml> tags and anything inbetween.  
    return Regex.Replace(input, @"<(.|\n)*?>", "*"); // remove any tags but not there content "<p>bob<span> johnson</span></p>" becomes "bob johnson"
}

1 个解决方案

#1


6  

Regex is not great for parsing XML or HTML. Take a look at the HTML Agility Pack

正则表达式不适合解析XML或HTML。看看HTML Agility Pack

HTML Agility Pack

HTML敏捷包

#1


6  

Regex is not great for parsing XML or HTML. Take a look at the HTML Agility Pack

正则表达式不适合解析XML或HTML。看看HTML Agility Pack

HTML Agility Pack

HTML敏捷包