title: Extracting submatches using boost regex in c++
body: <p>I'm trying to extract submatches from a text file using boost regex.  Currently I'm only returning the first valid line and the full line instead of the valid email address.  I tried using the iterator and using submatches but I wasn't having success with it.  Here is the current code:</p>
  
  <pre><code>if(Myfile.is_open()) {
      boost::regex pattern("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$");
      while(getline(Myfile, line)) {
              string::const_iterator start = line.begin();
              string::const_iterator end = line.end();
              boost::sregex_token_iterator i(start, end, pattern);
              boost::sregex_token_iterator j;
              while ( i != j) {
              cout &lt;&lt; *i++ &lt;&lt; endl;  
  
      } 
      Myfile.close(); 
  }
  </code></pre>