Windows Phone Developers

Sunday, June 1, 2008

Remove HTML Tags from String using .NET Regular Expressions

Strip HTML Tags from String using Regular Expressions

Sub Regex_Replace_Example()

Dim oReg As Regex

Dim sInput As String

Dim sOut As String

' Strip of Simple HTML Tags

sInput = "This is a HTML Text"

oReg = New Regex("")

sOut = oReg.Replace(sInput, "", "")

' Strip of Complex HTML Tags

sInput = "This is a HTML Text with images "

oReg = New Regex("")

sOut = oReg.Replace(sInput, "<[^<>]+>", "")

End Sub

See Also
Extract Ref Links From WebPage using VB.Net Regular Expressions
Remove HTML Tags from String using .NET Regular Expressions
VB.NET Regular Expression to Check URL
VB.NET Regular Expression to Check Email Addresses
VB.NET Regular Expression to Check MAC Address
Regular Expression to Check Zip Code
Validate eMail Addresses using VB.NET Function
Regular Expressions in Dot Net (.NET)

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

3 comments:

  1. If you are compiling with strict mode, you'll get this warning on line to call the replace method:

    warning BC42025: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.

    Any idea how the replace method should be called to avoid this warning?

    Strict mode set to true can not be set to false in my case.

    ReplyDelete
  2. Instead of this:

    oReg = New Regex("")
    sOut = oReg.Replace(sInput, "<[^<>]+>", "")

    Use this:
    sOut = Regex.Replace(sInput, "<[^<>]+>", "")

    To avoid this warning when compiling with strict mode set to true:

    warning BC42025: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.

    ReplyDelete