title: Regular expression group matching using Boost::regex
body: <p>I have strings of format:</p>
  
  <p><code>7XXXX 8YYYY 9ZZZZ 0LLLL 7XXXX 8YYYY 9ZZZZ 0LLLL</code>, </p>
  
  <ul>
  <li>where <code>7XXXX 8YYYY 9ZZZZ 0LLLL</code> groups can repeat any number of times;</li>
  <li>X, Y, Z, L are digits;</li>
  <li>Groups starting 7,8,9,0 all go in sequence</li>
  <li>there can be missing groups like <code>7XXXX 0LLLL 8YYYY 0LLLL 7XXXX 8YYYY 9ZZZZ 0LLLL</code></li>
  </ul>
  
  <p>I am trying to accomplish my goal using Boost::regex library.</p>
  
  <p>I want to split these groups and get them into an array or vector. For now I am trying to <code>cout</code> them.</p>
  
  <p>I am trying to do it this way, but I only can get full string match or last match in every of 7,8,9,0 groups, but not strings like these 7XXXX 8YYYY 9ZZZZ 0LLLL</p>
  
  <pre><code> const char* pat = "(([[:space:]]+7[0-9]{4}){0,1}([[:space:]]+8[0-9]{4}){0,1}([[:space:]]+9[0-9]{4}){0,1}([[:space:]]+0[0-9]{4}){0,1})+";;
   boost::regex reg(pat);
   boost::smatch match;
   string example= "71122 85451 75415 01102 75555 82133 91341 02134";
  
   const int subgroups[] = {0,1,2,3,4,5,6};
   boost::sregex_token_iterator i(example.begin(), example.end(), reg, subgroups);
   boost::sregex_token_iterator j;
  
   while (i != j)
   {
     cout &lt;&lt; "Match: " &lt;&lt; *i++ &lt;&lt; endl;
   }
  </code></pre>
  
  <p>Sample output:</p>
  
  <pre><code>Match: 71122 85451 75415 01102 75555 82133 91341 02134
  &lt;A bunch of empty "Match:" rows&gt;
  Match: 75555
  Match: 82133
  Match: 91341
  Match: 02134
  &lt;A bunch of empty "Match:" rows&gt;
  </code></pre>
  
  <p>But I want to get it like this:</p>
  
  <pre><code>71122 85451 
  75415 01102 
  75555 82133 91341 02134
  </code></pre>
  
  <p>I know I am doing it wrong, can't come up with something good using regex to do what I want :( Why can't I get all the recursive matches using parentheses? </p>