Hi all,
I'm trying to strip image tags using regular expression, I've had a few attempts now and have ended up using just one regexp , but, I don't think it's possible to loop through the parenthesized substrings (ie:$1) like I was hoping.
here is a quick messy example I was testing.
and the out come was:
the out come I'm trying to achieve is:
if anyone could show me the right/proper way of doing this I'd be very grateful.
Thanks
I'm trying to strip image tags using regular expression, I've had a few attempts now and have ended up using just one regexp , but, I don't think it's possible to loop through the parenthesized substrings (ie:$1) like I was hoping.
here is a quick messy example I was testing.
Code:
<script>
var string='<img src="[URL unfurl="true"]http://www.tipmaster.com/images/afro.gif"[/URL] id="blah"> test <br> <img src="[URL unfurl="true"]http://www.tipmaster.com/images/afro2.gif">test[/URL] text,<img src="[URL unfurl="true"]http://www.tipmaster.com/images/bluegreedy.gif"[/URL] /> doesn't need stripping--> [URL unfurl="true"]http://www.tipmaster.com/images/neutral.gif[/URL] <a href="[URL unfurl="true"]http://example.com">link</a>';[/URL]
var reimgtag=/<img \S*(http:\/\/\S*(jpe?g|gif|bmp|png))\b[^>]*>/ig;
var matchreimg = string.match(reimgtag);
//alert(matchreimg[0].toString());
for(i=0;i<matchreimg.length;i++){
//alert(matchreimg);
//alert(RegExp.$1);
string = string.replace(matchreimg[i],' '+RegExp.$1+' ');
}
document.write(string+'<br /><br /> : <b>'+matchreimg.length);
</script>
and the out come was:
Code:
[URL unfurl="true"]http://www.tipmaster.com/images/bluegreedy.gif[/URL] test <br> text, doesn't need stripping--> [URL unfurl="true"]http://www.tipmaster.com/images/neutral.gif[/URL] <a href="[URL unfurl="true"]http://example.com">link</a>[/URL]
the out come I'm trying to achieve is:
Code:
[URL unfurl="true"]http://www.tipmaster.com/images/afro.gif[/URL] test <br> [URL unfurl="true"]http://www.tipmaster.com/images/afro2.gif[/URL] test text, [URL unfurl="true"]http://www.tipmaster.com/images/bluegreedy.gif[/URL] doesn't need stripping--> [URL unfurl="true"]http://www.tipmaster.com/images/neutral.gif[/URL] <a href="[URL unfurl="true"]http://example.com">link</a>[/URL]
if anyone could show me the right/proper way of doing this I'd be very grateful.
Thanks