I'm trying to generate an array of elements that are either text or an "image block".
var str : String = "";
for (var i : int = 0; i < 100; i++)
{
str += (Math.random() > .5) ? "<img>amazed</img>" : "<img>happy</img>";
}
var arr : Array = str.split(/(<img>\w+<\/img>)/);
I want the array to have a length of 100 and for each element in the array to reflect either <img>amazed</img> or <img>happy</img>. Instead, the length is 201 and every other element is an empty String.
Is there a simple way to change the regex to avoid doubling the size of the array?