I want to strip the <img>
tags and it's contents out of my string that is returned from the database.
Example string
//I want to retrive dummy texts from my string.
var string = "<img src='test.jpg'/>dummy texts <img src='text.jpg'/> dummby text dummy texts";
I have tried
if (string.indexOf('<img') != -1) {
var newString = $(string).filter(function() {
return this.tagName != 'img';
}).text();
}
However, my DB has crappy data and sometimes return
//There is no closure for image tag.
var string = "<img src='test.jpg'/>dummy texts <img src='text.jpg'/> dummby text dummy texts";
and my code would strip the entire string.
The image tag positions vary.
How do I strip the <img>
tags efficiently?