Для меня важна функция findall, поэтому я упаковал ответ lawnsea в функцию для простой копирования и вставки.
function findall(regex_pattern, string_)
{
var output_list = [];
while (true)
{
var a_match = regex_pattern.exec(string_);
if (a_match)
{
// get rid of the string copy
delete a_match.input;
// store the match data
output_list.push(a_match);
}
else
{
break;
}
}
return output_list;
}
пример использования:
console.log( findall(/blah/g,'blah1 blah2') )
выходов :
[ [ 'blah', index: 0 ], [ 'blah', index: 6 ] ]