Malik.Akhtar Malik.Akhtar - 1 year ago 83
C# Question

How can i remove HTML Tags from String by REGEX?

I am fetching data from Mysql but the issue is "HTML tags i.e.


also being fetched with my data i just need "LARGE" and "Lamb" from above line. How can I separate/remove HTML tags from String?

Answer Source

try this

// erase html tags from a string
public static string StripHtml(string target)
//Regular expression for html tags
Regex StripHTMLExpression = new Regex("<\\S[^><]*>", RegexOptions.IgnoreCase |   RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Compiled);

return StripHTMLExpression.Replace(target, string.Empty);


string htmlString="<div><span>hello world!</span></div>";
string strippedString=StripHtml(htmlString);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download