PDA

View Full Version : RegExp in vb/asp


brazenskies
10-15-2008, 04:49 PM
I need to remove anything in image tags from a paragraph of text.

The paragraph currently looks like this...


here is a paragraph of some text <img src="image.jpg" /> and here is some more...


I need to strip out the whole img tag so I end up with this...


here is a paragraph of some text and here is some more...


I really know nothing about regExp and having trouble finding any solutions to this so hoping someone might be able to help.

I managed to come up with this, to strip replace everything that comes after the tag opener, but I need to somehow change it so that it includes everything again after the closing tag...


str = "here is a paragraph of some text <img src="image.jpg" /> and here is some more..."
set img = new RegExp
set endimg = new RegExp
img.pattern = "<img.*$"

gstr = img.replace(str,"")


Thanks in advance!

Spudhead
10-15-2008, 05:05 PM
Would something like this work?

img.Pattern = "<img[^>]*>"

Basically... match the start of the img tag, keep matching anything that isn't the end of the tag, then match the end of the tag.

NB. regExp's aren't my strong point either ;)

brazenskies
10-15-2008, 05:32 PM
nice one, I'll give it a try when I get back into work tomorrow!

Cheers!

brazenskies
10-15-2008, 05:36 PM
just tried it now actually and it works a treat!

Thanks again