HTML tags verwijderen uit tekst

Functie heeft een verwijzing nodig.
In de VBE, Extra | Verwijzingen
Microsoft VBScript Regular Expressions 5.5

Handige functie om de HTML tags uit een webpage te verwijderen.

Function stripHTML(strHTML)

    'Strips the HTML tags from strHTML
    Dim objRegExp, strOutput
    Set objRegExp = New Regexp

    objRegExp.IgnoreCase = True
    objRegExp.Global = True
    objRegExp.Pattern = "<(.|\n)+?>"

    'Replace all HTML tag matches with the empty string
    strOutput = objRegExp.Replace(strHTML, "")

    'Replace all < and > with &lt; and &gt;
    strOutput = Replace(strOutput, "<", "&lt;")
    strOutput = Replace(strOutput, ">", "&gt;")
    
    'Return the value of strOutput
    stripHTML = strOutput

    Set objRegExp = Nothing
End Function

Leave a Reply

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