So I was toying with the new RegExp stuff and low and behold it only matches the first instance and there’s no flag to turn on match all? Atleast nothing I could find… if there is someone tell me otherwise the below will get every match and put them into an array
var input:String = getInput(5); // input string
var output:Array = new Array(); // output array
var pattern:RegExp = /[A-Z]+/g; // match all uppercase strings only
// loop through them all we avoid recursion by not putting this in a function but also only run it as needed
var i:int = 0;
while(i < input.length)
{
var match:Object = pattern.exec(input);
if(match !== null)
{
output.push(match);
i = pattern.lastIndex-1;
}
else
{
break;
}
}
// trace matches that are now in an array
trace(output);
// provides a set number of HELLO all caps that the regex will match while putting in filler copy to ignore as well
function getInput(len:int):String
{
var output:String = "";
for(var i:Number = 0; i < len; i++)
{
output += "HELLO"+i+" filler crap copy";
}
return output;
}
Enjoy