タイトルで示されている提案された質問に固執するために、実際にはを使用して文字列内の各一致を反復できますString.prototype.replace()。たとえば、次の例では、正規表現に基づいてすべての単語の配列を取得しています。
function getWords(str) {
  var arr = [];
  str.replace(/\w+/g, function(m) {
    arr.push(m);
  });
  return arr;
}
var words = getWords("Where in the world is Carmen Sandiego?");
// > ["Where", "in", "the", "world", "is", "Carmen", "Sandiego"]
キャプチャグループまたは各マッチのインデックスさえ取得したい場合は、それも実行できます。以下は、一致全体、最初のキャプチャグループ、およびインデックスとともに各一致が返される方法を示しています。
function getWords(str) {
  var arr = [];
  str.replace(/\w+(?=(.*))/g, function(m, remaining, index) {
    arr.push({ match: m, remainder: remaining, index: index });
  });
  return arr;
}
var words = getWords("Where in the world is Carmen Sandiego?");
上記を実行wordsすると、次のようになります。
[
  {
    "match": "Where",
    "remainder": " in the world is Carmen Sandiego?",
    "index": 0
  },
  {
    "match": "in",
    "remainder": " the world is Carmen Sandiego?",
    "index": 6
  },
  {
    "match": "the",
    "remainder": " world is Carmen Sandiego?",
    "index": 9
  },
  {
    "match": "world",
    "remainder": " is Carmen Sandiego?",
    "index": 13
  },
  {
    "match": "is",
    "remainder": " Carmen Sandiego?",
    "index": 19
  },
  {
    "match": "Carmen",
    "remainder": " Sandiego?",
    "index": 22
  },
  {
    "match": "Sandiego",
    "remainder": "?",
    "index": 29
  }
]
PHPで使用可能なものと同様の複数の出現に一致させるために、preg_match_allこのタイプの考え方を使用して独自のものを作成したり、のようなものを使用したりできますYourJS.matchAll()。YourJSは、多かれ少なかれ、この関数を次のように定義しています。
function matchAll(str, rgx) {
  var arr, extras, matches = [];
  str.replace(rgx.global ? rgx : new RegExp(rgx.source, (rgx + '').replace(/[\s\S]+\//g , 'g')), function() {
    matches.push(arr = [].slice.call(arguments));
    extras = arr.splice(-2);
    arr.index = extras[0];
    arr.input = extras[1];
  });
  return matches[0] ? matches : null;
}
               
              
replaceここでの使用を推奨する人がいないのは少し奇妙です。var data = {}; mystring.replace(/(?:&|&)?([^=]+)=([^&]+)/g, function(a,b,c,d) { data[c] = d; });完了しました。JavaScriptの「matchAll」は、文字列ではなく置換ハンドラー関数で「置換」されます。