?
Solved

VB6 and MS Regular Expr - strip HTML

Posted on 2007-07-30
3
Medium Priority
?
518 Views
Last Modified: 2011-10-03
Using VB6 and MS Regular Expressions, I need to be able to strip out the HTML from a string, leaving just plain text that was located outside the HTML tags. Somewhere I saw a regular Expression to do this. What is the pattern and how do I do I do it in VB6? A simple code sample would be appreciated.
0
Comment
Question by:dnotestine
3 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 2000 total points
ID: 19593708
The function below removes all HTML tags from a string. Carriage return line feed pairs are also removed.

[Begin Code Segment]

Public Function RemoveHTMLTags( _
      ByVal HTMLText As String _
   ) As String
   
' Remove all HTML tags from the text and return the cleaned text.
   
   Dim RegExp As Object
   Dim Matches As Object
   Dim Match As Object
   
   Set RegExp = CreateObject("VBScript.RegExp")
   RegExp.IgnoreCase = True
   RegExp.Global = True
   
   HTMLText = Replace(HTMLText, vbCrLf, "")
   RegExp.Pattern = "<!--(.*)-->"
   HTMLText = RegExp.Replace(HTMLText, "$1")
   RegExp.Pattern = "<(?:.|\n)*?>"
   RemoveHTMLTags = RegExp.Replace(HTMLText, "")

End Function

[End Code Segment]

Kevin
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 19596251
My example is not VB6 but it shows how RegExp works:

<script language="VBSCRIPT">

theString = "<b>Some</b>string<br>with<h1>Tags</h1>"

Set theExp = new RegExp

theExp.Pattern = "<[^>]+>"
theExp.Global = True

MsgBox theExp.Replace(theString, "")

</script>


0
 

Author Comment

by:dnotestine
ID: 19596772
Your Function worked perfectly in VB6. I just copied and pasted.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Starting up a Project

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question