title: Get index of each capture in a JavaScript regex
body: <p>I want to match a regex like <code>/(a).(b)(c.)d/</code> with <code>"aabccde"</code>, and get the following information back:</p>
  
  <pre><code>"a" at index = 0
  "b" at index = 2
  "cc" at index = 3
  </code></pre>
  
  <p>How can I do this? String.match returns list of matches and index of the start of the complete match, not index of every capture.</p>
  
  <p>Edit: A test case which wouldn't work with plain indexOf</p>
  
  <pre><code>regex: /(a).(.)/
  string: "aaa"
  expected result: "a" at 0, "a" at 2
  </code></pre>
  
  <p>Note: The question is similar to <a href="https://stackoverflow.com/questions/11568345/javascript-regex-how-to-find-index-of-each-subexpression">Javascript Regex: How to find index of each subexpression?</a>, but I cannot modify the regex to make every subexpression a capturing group.</p>