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

Ash*_*sik 4 c# regex

我有一些代码删除所有的HTML标签,但我想删除所有的HTML,但除了</td></tr>标签.

如何才能做到这一点?

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"
}
Run Code Online (Sandbox Code Playgroud)

小智 6

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

HTML敏捷包