title: JavaScript regular expression iterator to extract groups
body: <p>let's say we have the following text: "1 a,2 b,3 c,4 d" and the following expression: /\d (\w)/g</p>
  
  <p>what we want to do is to extract a, b, c, d as denoted by the regular expression.</p>
  
  <p>unfortunately "1 a,2 b,3 c,4 d".match(/\d (\w)/g) will produce an array: 1 a,2 b,3 c,4 d and RegExp.$1 will contain only the groups from the last match, i.e. RegExp.$1 == 'd'.</p>
  
  <p>how can I iterate over this regex so that I can extract the groups as well... I am looking for a solution that is also memory efficient, i.e. some sort of iterator object</p>
  
  <p>EDIT:
  It needs to be generic. I am only providing a simple example here. One solution is to loop over the array and reapply the regex for each item without the global flag but I find this solution a bit stupid although it seems to be like the only way to do it.</p>