.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh

Home >> Code Snippets >> Regular Expressions >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Remove HTML Tag from a string using regular expression

Posted By:Amit Mehra       Posted Date: March 01, 2011    Points: 40    Category: Regular Expressions    URL: http://www.dotnetspark.com  

This code sample can be used to remove or strip html tags from the given string using Regular Expression in C# or VB.NET

This code remove all the HTML tags like , , etc..that means any word inside < or > will be removed.

You have to add using System.Text.RegularExpressions; Namespace to used below code because it used regular expression

    public static string RemoveHTMLTag(string text)
        return Regex.Replace(text, @"<(.|\n)*?>", string.Empty);

in VB.Net

Public Shared Function RemoveHTMLTag(text As String) As String
	Return Regex.Replace(text, "<(.|\n)*?>", String.Empty)
End Function


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend