title: Why is my regex causing an infinite loop?
body: <p>I'm new to the c++ <code>regex</code> library. I noticed while following the documentation on cplusplus.com that in their example, the condition they used to terminate the iteration loop would always return <code>true</code> if I used a regex that matched the entire target sequence. Ideally, the loop should match once and then terminate. Here's my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;regex&gt;
  
  int main()
  {
      std::string str("Foo bar");
      std::regex reg("(.|[\r\n])*"); // Match the whole string
  
      std::regex_iterator&lt;std::string::iterator&gt; rit(str.begin(), str.end(), reg);
      std::regex_iterator&lt;std::string::iterator&gt; rend;
  
      while (rit != rend) // For some reason this is always true
      {
          std::cout &lt;&lt; "Infinite loop!" &lt;&lt; std::endl;
          rit++;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>