Remove HTML tags from string including &nbsp in C#

If you can’t use an HTML parser oriented solution to filter out the tags, here’s a simple regex for it.

string noHTML = Regex.Replace(inputHTML, @"<[^>]+>|&nbsp;", "").Trim();

You should ideally make another pass through a regex filter that takes care of multiple spaces as

string noHTMLNormalised = Regex.Replace(noHTML, @"\s{2,}", " ");

Leave a Comment