title: Get the index of all matches using regex_search?
body: <p>I just start to learn how to use <code>regex</code> for string handling (<code>C++11</code> new feature). Please pardon me if the following question is too silly.</p>
  
  <p>Currently I apply the following code to get the index of all matches:</p>
  
  <pre><code>string str = "aaabxxxaab";
  regex rx("ab");
  
  vector&lt;int&gt; index_matches; // results saved here (should be {2, 8})
  
  int track = 0;
  smatch sm;
  while (regex_search(str, sm, rx))
  {
      index_matches.push_back(track+sm.position());
  
      string tmp = sm.suffix().str();
      track += str.length() - tmp.length(); // update base index
  
      str = tmp;
  }
  </code></pre>
  
  <p>It works OK, but I have to update <code>track</code> (base index) manually each time to make it work correctly. </p>
  
  <p>At the same time, I noticed that there are already <code>smatch::size()</code> and <code>smatch::position()</code>, which I want to combine using to achieve the goal. The following is the code I want to combine them together but cannot work (i.e. always get only <code>{2}</code>).</p>
  
  <pre><code>string str = "aaabxxxaab";
  regex rx("ab");
  
  vector&lt;int&gt; index_matches; // results saved here 
                             // (should be {2, 8}, but always get only {2})
  
  smatch sm;
  regex_search(str, sm, rx);
  for (int i=0; i&lt;sm.size(); i++)
      index_matches.push_back(sm.position(i));
  </code></pre>
  
  <p>Can someone tell me how to correctly use <code>smatch::size()</code> and <code>smatch::position()</code> to get all matched indexes?</p>