javascript аналог preg_match_all
function preg_match_all(regex, haystack) {
'use strict';
var globalRegex = new RegExp(regex, 'g'),
nonGlobalRegex = new RegExp(regex),
nonGlobalMatch,
globalMatch = haystack.match(globalRegex),
matchArray,
i;
matchArray = [];
for (i = 0; i < globalMatch.length; i += 1) {
nonGlobalMatch = globalMatch[i].match(nonGlobalRegex);
matchArray.push(nonGlobalMatch[1]);
}
return matchArray;
}


Комментарии
Получится:
function preg_match_all(regex, haystack) {
var globalRegex = new RegExp(regex, 'g');
var globalMatch = haystack.match(globalRegex);
matchArray = new Array();
nonGlobalRegex = new RegExp(regex);
for (var i in globalMatch) {
nonGlobalMatch = globalMatch.match(nonGlobalRegex);
matchArray.push(nonGlobalMatch[1]);
}
return matchArray;
}