views:

58

answers:

2

I'm trying to find a regex for VBScript to remove some html tags and their content from a string.

The string is,

<H2>Title</H2><SPAN class=tiny>Some
text here</SPAN><LI>Some list
here</LI><SCRITP>Some script
here</SCRITP><P>Some text here</P>

Now, I'd like to EXCLUDE <SPAN class=tiny>Some text here</SPAN> and <SCRITP>Some script here</SCRITP>

Maybe someone has a simple solution for this, thanks.

A: 

You could do this a lot easier using css:

span.tiny {
    display: none;
}

or using jQuery:

$("span.tiny").hide();
krock
That won't remove the script tags.
Jan Goyvaerts
A: 

This should do the trick in VBScript:

Dim myRegExp, ResultString
Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "<span class=tiny>[\s\S]*?</span>|<script>[\s\S]*?</script>"
ResultString = myRegExp.Replace(SubjectString, "")

SubjectString is the variable with your original HTML and ResultString receives the HTML with all occurrences of the two tags removed.

Note: I'm assuming scritp in your sample is a typo for script. If not, adjust my code sample accordingly.

Jan Goyvaerts