According to MDC https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp/exec the following code should log each of the global matches for this regexp.
var str = "(^|\\+)(1\\+1)($|\\+)";
var regex = new RegExp(str, "g");
var result;
var testString = "1+1+1";
while ((result = regex.exec(testString)) != null)
{
console.log(result);
}
But all I get is the first match and then the loop finishes. Any ideas why.