StripHTML with ASP RegEx

The following function will strip all html tags from a text. Can be usefull for a lot of things where you don´t want any html code to screw up the design. Found it somewhere on the internet a few years back, very usefull!

Function StripHTML(ByRef asHTML)
 Dim loRegExp ‘ Regular Expression Object

 ‘ Create built In Regular Expression object
 Set loRegExp = New RegExp
 loRegExp.Global = True
 ‘ Set the pattern To look For HTML tags
 loRegExp.Pattern = “<[^>]*>”

 ‘ Return the original String stripped of HTML
 StripHTML = loRegExp.Replace(asHTML,” “)

 ‘ Release object from memory
 Set loRegExp = Nothing

End function

To use this function in your page, just do the following (also be shure you included the function in your page):

Dim MyString
MyString = StripHTML(<yourstring>)

Replace <yourstring> with your own input.

One Response to StripHTML with ASP RegEx

  1. Roger says:

    Thx for the code.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Seo Packages