Example: Stripping HTML tags via Regex

mline

Newbie
Joined
Jan 30, 2010
Messages
49
Reaction score
19
Code:
'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.
 
Last edited:
Back
Top