title: Delete paragraph containing string in python
body: <p>I have a file that contains blocks of information beginning and ending with the same phrase:</p>
  <pre><code># Info block
  Info line 1
  Info line 2
  Internal problem
  ENDOFPARAMETERPOINT
  </code></pre>
  <p>I am trying to write a python code that deletes the entire block beginning with # Info block and ending with ENDOFPARAMETERPOINT once it detects the phrase Internal problem.</p>
  <pre><code>finds = '# Info block\nInfo line 1\nInfo line 2\nInternal problem\nENDOFPARAMETERPOINT'
  
  with open(filename,&quot;r+&quot;) as fp:
       pattern = re.compile(r'[,\s]+' + re.escape(finds) + r'[\s]+')
       textdata = fp.read()
       line = re.sub(pattern,'',textdata)
       fp.seek(0)
       fp.write(line)
  </code></pre>
  <p>This code only works for one line but not the entire paragraph. Any suggestions are appreciated.</p>
  <p>EDIT:</p>
  <p>The code that works now is:</p>
  <pre><code>with open(filename,&quot;r+&quot;) as fp:
       pattern = re.compile(re.escape(finds))
       textdata = fp.read()
       line = re.sub(pattern,'',textdata)
       fp.seek(0)
       fp.write(line)
       fp.truncate()
  </code></pre>