ampu
ampu

Reputation: 11

How to remove some html tags?

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.

Upvotes: 1

Views: 1605

Answers (3)

Sandwich
Sandwich

Reputation: 2289

I think you want this

$(function(){
$('span.tiny').remove();
$('script').remove();
})

Upvotes: 0

Jan Goyvaerts
Jan Goyvaerts

Reputation: 21999

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.

Upvotes: 4

krock
krock

Reputation: 29619

You could do this a lot easier using css:

span.tiny {
    display: none;
}

or using jQuery:

$("span.tiny").hide();

Upvotes: 0

Related Questions