If you use .exec , you must run it several times to get all the results:
In the following example, the g (global) flag is set in the regular expression, so you can use exec () several times to find multiple matches:
var myPattern:RegExp = /(\w*)sh(\w*)/ig; var str:String = "She sells seashells by the seashore"; var result:Object = myPattern.exec(str); while (result != null) { trace (result.index, "\t", result); result = myPattern.exec(str); }
Source: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/RegExp.html
A better alternative is probably to use String.match :
If the pattern is a regular expression, to return an array with more than one matching substring, the g (global) flag must be set in the regular expression
An example should be (not verified):
var regEx:RegExp = /(?:^|\s)(\#[^\s$]+)/g; var txt:String = "This #asd is a test tweet #hash1 test #hash2 test"; var matches:Object = txt.match(regEx);
source share