title: Find mismatch in boost match results
body: <p>I'm using boost::regex_match and I'm trying to find a function to obtain the position where the regular expression stopped matching. I couldn't find any attribute in the boost::match_results object, but several code snippets in which boost::regex_search is used to show the submatches. Am I on the right path with my implementation or do I've to do something different in order to achieve that? My code looks as follows:</p>
  
  <pre><code>int main(int args, char** argv)
  {
      boost::match_results&lt;std::string::const_iterator&gt; what;
  
      if(args == 3) 
      {
          std::string text(argv[1]);
          boost::regex expression(argv[2]);
  
          std::cout &lt;&lt; "Text : " &lt;&lt; text &lt;&lt; std::endl;
          std::cout &lt;&lt; "Regex: " &lt;&lt; expression &lt;&lt; std::endl;
  
          if(boost::regex_match(text, what, expression, boost::match_default) != 0) 
          {
              int i = 0;
  
              for(boost::match_results&lt;std::string::const_iterator&gt;::const_iterator it=what.begin(); it!=what.end(); ++it) 
              {
                  std::cout &lt;&lt; "[" &lt;&lt; (i++) &lt;&lt; "] " &lt;&lt; it-&gt;str() &lt;&lt; std::endl;
              }
              std::cout &lt;&lt; "Matched!" &lt;&lt; std::endl;
          } 
          else 
          {
              std::string::const_iterator start = text.begin();
              std::string::const_iterator end   = text.end();
  
              while(boost::regex_search(start, end, what, expression)) 
              {
                  std::string submatch(what[1].first, what[1].second);
                  std::cout &lt;&lt; submatch &lt;&lt; std::endl;
                  start = what[0].second;
              }
              std::cout &lt;&lt; "Didn't match!" &lt;&lt; std::endl;
          }
      } //if(args == 3)
      else 
      {
          std::cout &lt;&lt; "Invalid usage! $&gt; ./boost-regex &lt;text&gt; &lt;regex&gt;" &lt;&lt; std::endl;
      }
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>$&gt; ./boost_regex "We're building it up to burn it down" ".*(build.*)(to.*)(burn.*)"
  Text : We're building it up to burn it down
  Regex: .*(build.*)(to.*)(burn.*)
  [0] We're building it up to burn it down
  [1] building it up
  [2] to
  [3] burn it down
  Matched!
  
  $&gt; ./boost_regex "We're building it up to burm it down" ".*(build.*)(to.*)(burn.*)"
  Text : We're building it up to burm it down
  Regex: .*(build.*)(to.*)(burn.*)
  Didn't match!
  </code></pre>
  
  <p>For the last input I'd like to have the something similar to:</p>
  
  <pre><code>Text : We're building it up to burm it down
  Regex: .*(build.*)(to.*)(burn.*)
  [0] We're building it up to
  [1] building it up
  [2] to
  Didn't match!
  </code></pre>
  
  <p>Thanks in advance ...</p>