+ 1

remove html tags in the string..

I need to remove all HTML tags in the strings expect <p>,<br>,<strong>,<li>,<ol> Please provide a solution. I have tried the code Text = Regex.Replace(Text, "(?i)<(?!p|/p|br|/br|ul|/ul|li|/li|ol|/ol|strong|/strong|b|/b|em|/em|i|/i).*?>", String.Empty); But it will also remove the less than and greater than cases on the string.

3rd Mar 2020, 5:28 PM
Pon Mani
Pon Mani - avatar
2 Respostas
+ 2
You could Parse your text in an XmlDocument object, and on the root element call InnerText to extract the text.
3rd Mar 2020, 9:56 PM
JaScript
JaScript - avatar
+ 1
Hi @Ja Play your answer is only acceptable for valid HTML Tags only. But my text has invalid tags also. So give a better solution. For Example Text = "<p class = etc> Ponmani <br> some text <p> closed where 5 < 7 and 11 > 7 </p>" I need this output. <p>Ponmani <br> some text <p> closed where 5 < 7 and 11 > 7 </p> But that will remove HTML tags as followed by <p>Ponmani <br> some text <p> closed where 5 7 </p>
4th Mar 2020, 6:33 PM
Pon Mani
Pon Mani - avatar