title: regex catastrophic backtrack issue
body: <p>I am trying to scan the following type of files. Files exists of specific blocks that alternate serially, for example:</p>
  
  <pre><code>**Block A starts**
  -some data- **Block B starts**
  -some data- ***END***---- **Block A starts**
  -some data- **Block B starts**
  -some data- ***END***---- etc etc.
  </code></pre>
  
  <p>This file can be very large (for example 500gb).
  I am trying to scan the file using a regex to get the data of each block, for example: </p>
  
  <blockquote>
    <p>[[block A data, block B data], [block A data, block B data]]</p>
  </blockquote>
  
  <p>The way i was trying to do it at start was with this regex:</p>
  
  <pre><code>"Block A starts(.+?)Block B starts(.+?)END"
  </code></pre>
  
  <p>if the file was in this format, everything was ok, but this regex had issues if for example Block B did not appear in the log file. I think i had the backtracking issue. I read that you had to use atomic groups to remove backtracking, so i wrote this regex:</p>
  
  <pre><code>"(?=(?P&lt;group1&gt;.+?Block B starts))(?P=group1)(?=(?P&lt;group2&gt;.+?END))(?P=group2)"
  </code></pre>
  
  <p>but still had the same issue. I also tried this regex in order to make it stop if it reaches the end of file, but still ahd no success.</p>
  
  <pre><code>"(?=(?P&lt;group1&gt;.+?(?:Block B starts|\Z)))(?P=group1)(?=(?P&lt;group2&gt;.+?(?:END|\Z)))(?P=group2)"
  </code></pre>
  
  <p>If the regex is not matching the file correctly, it takes forever to complete with large files.</p>
  
  <p>Anyone has any idea how i can fix the regex in order both to match correctly the file but also make it fail quickly if any of those blocks does not exist.</p>
  
  <p>(I am using python with the default re module)</p>