Preg_match_all for JavaScript
// Add to RegExp prototype RegExp.prototype.execAll = function(string) { var matches = []; var match = null; while ( (match = this.exec(string)) != null ) { var matchArray = []; for (var i in match) { if (parseInt(i) == i) { matchArray.push(match[i]); } } matches.push(matchArray); } return matches; } // Example var someTxt = 'abc123 def456 ghi890'; var results = /[a-z]+(d+)/g.execAll(someTxt); console.log(results); // Output [["abc123", "123"], ["def456", "456"], ["ghi890", "890"]]