# \[RegExp\]: Matching All

**URL:** <https://forum.kirupa.com/t/regexp-matching-all/231029>\
**Category:** flash\
**Created:** [July 1, 2007, 12:22pm UTC](https://forum.kirupa.com/t/regexp-matching-all/231029 "2007-07-01T12:22:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flaevo](https://avatars.discourse-cdn.com/v4/letter/f/bbce88/32.png) [@Flaevo](https://forum.kirupa.com/u/Flaevo)\
**Post date:** [July 1, 2007, 12:22pm UTC](https://forum.kirupa.com/t/regexp-matching-all/231029/1 "2007-07-01T12:22:27Z")

</div>

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

```auto

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 🙂
