remove only some html tags on c#

c#, html

Solution

Use `Regex`:

var result = Regex.Replace(html, @"</?DIV>", "");

UPDATED

as you mentioned, by this code, regex removes all tages else `B`

var hmtl = "<DIV><B> xpto </B></DIV>";
var remainTag = "B";
var pattern = String.Format("(</?(?!{0})[^<>]*(?<!{0})>)", remainTag );
var result =  Regex.Replace(hmtl , pattern, "");

Problem

I have a string: ``` string hmtl = "<DIV><B> xpto </B></DIV> ``` and need to remove the tags of `<div>` and `</DIV>`. With a result of : `<B> xpto </B>` Just `<DIV> and </DIV>` without the removal of a lot of html tags, but save the `<B> xpto </B>`.

Original source

Related problems