1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Example: Stripping HTML tags via Regex

Discussion in 'Visual Basic .NET' started by mline, Feb 19, 2010.

  1. mline

    mline Newbie

    Jan 30, 2010
    Likes Received:
    'Imports System.Text.RegularExpressions
    Dim htmlData As String '= Whatever data from html page
    Dim strippedText As String
    strippedText = Regex.Replace(htmlData, "</??[^>]*>", "")
    'For c# just insert goofy squiggles where necessary.
    I was just needing to strip all of the html tags out of some webmail email bodies. I figured I'd share for those that maybe aren't too familiar with regular expressions or anyone not realizing the replace functionality of it. The regex pattern isnt perfect. It could be cleaned up and made more fault tolerant.

    PS-If you are interested in using more regular expressions but are a beginner I definitely suggest getting RegexBuddy. It helps you to create your patterns, test them against text and can even provide language specific code.
    • Thanks Thanks x 5
    Last edited: Feb 20, 2010