title: re.findall regex hangs or very slow
body: <p>My input file is a large txt file with concatenated texts I got from an open text library. I am now trying to extract only the content of the book itself and filter out other stuff such as disclaimers etc. So I have around 100 documents in my large text file (around 50 mb). </p>
  
  <p>I then have identified the start and end markers of the contents themselves, and decided to use a Python regex to find me everything between the start and end marker. To sum it up, the regex should look for the start marker, then match everything after it, and stop looking once the end marker is reached, then repeat these steps until the end of the file is reached.</p>
  
  <p>The following code works flawlessly when I feed a small, 100kb sized file into it:</p>
  
  <pre><code>import codecs
  import re
  
  outfile = codecs.open("outfile.txt", "w", "utf-8-sig")
  inputfile = codecs.open("infile.txt", "r", "utf-8-sig")
  filecontents = inputfile.read()
  for result in re.findall(r'START\sOF\sTHE\sPROJECT\sGUTENBERG\sEBOOK.*?\n(.*?)END\sOF\THE\sPROJECT\sGUTENBERG\sEBOOK', filecontents, re.DOTALL):
      outfile.write(result)
  outfile.close()
  </code></pre>
  
  <p>When I use this regex operation on my larger file however, it will not do anything, the program just hangs. I tested it overnight to see if it was just slow and even after around 8 hours the program was still stuck. </p>
  
  <p>I am very sure that the source of the problem is the 
      (.*?)
  part of the regex, in combination with re.DOTALL. 
  When I use a similar regex on smaller distances, the script will run fine and fast.
  My question now is: why is this just freezing up everything? I know the texts between the delimiters are not small, but a 50mb file shouldn't be too much to handle, right?
  Am I maybe missing a more efficient solution?</p>
  
  <p>Thanks in advance.</p>