title: How to check which matching group was used to match (boost-regex)
body: <p>I'm using boost::regex to parse some formatting string where '%' symbol is escape character. Because I do not have much experience with boost::regex, and with regex at all to be honest I do some trial and error. This code is some kind of prototype that I came up with.</p>
  
  <pre><code>std::string regex_string = 
              "(?:%d\\{(.*)\\})|"                   //this group will catch string for formatting time
              "(?:%([hHmMsSqQtTlLcCxXmMnNpP]))|"    //symbols that have some meaning
              "(?:\\{(.*?)\\})|"                    //some other groups
              "(?:%(.*?)\\s)|"
              "(?:([^%]*))";
  
      boost::regex regex;
      boost::smatch match;
  
      try
      {
          regex.assign(regex_string, boost::regex_constants::icase);
          boost::sregex_iterator res(pattern.begin(), pattern.end(), regex);
          //pattern in line above is string which I'm parsing
          boost::sregex_iterator end;
          for(; res != end; ++res)
          {
              match = *res;
              output &lt;&lt; match.get_last_closed_paren();
              //I want to know if the thing that was just written to output is from group describing time string
              output &lt;&lt; "\n";
          }
  
  
      }
      catch(boost::regex_error &amp;e)
      {
          output&lt;&lt;"regex error\n";
      }
  </code></pre>
  
  <p>And this works pretty good, on the output I have exactly what I want to catch. But I do not know from which group it is. I could do something like <code>match[index_of_time_group]!=""</code> but this is kind of fragile, and doesn't look too good. If I change <code>regex_string</code> index that was pointing on group catching string for formatting time could also change. </p>
  
  <p>Is there a neat way to do this? Something like naming groups? I'll be grateful for any help.</p>