I\'m writing a chrome extension, and I need to split a string that contains only text and img tags, so that every element of the array is either letter or img tag. For example,
You can use exec instead of split to obtain the separated elements:
var str = 'abcd';
var myRe = /]*>|[a-z]/gi;
var match;
var res= new Array();
while ((match = myRe.exec(str)) !== null) {
res.push(match[0]);
}
console.log(res);