title: Extract a string between other two in Python
body: <p>I am trying to extract the comments from a fdf (PDF comment file). In practice, this is to extract a string between other two. I did the following:</p>
  <ol>
  <li>I open the fdf file with the following command:</li>
  </ol>
  <pre><code>import re
  import os
  
  os.chdir(&quot;currentworkingdirectory&quot;)
  archcom =open(&quot;comentarios.fdf&quot;, &quot;r&quot;)
  cadena = archcom.read()
  </code></pre>
  <ol start="2">
  <li>With the opened file, I create a string called cadena with all the info I need. For example:</li>
  </ol>
  <pre><code>cadena = &quot;\n215 0 obj\n&lt;&lt;/D[2.0 2.0]/S/D&gt;&gt;\nendobj\n216 0 obj\n&lt;&lt;/D[2.0 2.0]/S/D&gt;&gt;\nendobj\n217 0 obj\n&lt;&lt;/D[2.0 2.0]/S/D&gt;&gt;\nendobj\n218 0 obj\n&lt;&lt;/W 3.0&gt;&gt;\nendobj\n219 0 obj\n&lt;&lt;/W 3.0&gt;&gt;\nendobj\ntrailer\n&lt;&lt;/Root 1 0 R&gt;&gt;\n%%EOF\n&quot;
  </code></pre>
  <ol start="3">
  <li>I try to extract the needed info with the following line:</li>
  </ol>
  <pre><code>a = re.findall(r&quot;nendobj(.*?)W 3\.0&quot;,cadena)
  </code></pre>
  <p>Trying to get:</p>
  <pre><code>a = &quot;n216 0 obj\n&lt;&lt;/D[2.0 2.0]/S/D&gt;&gt;\nendobj\n217 0 obj\n&lt;&lt;/D[2.0 2.0]/S/D&gt;&gt;\nendobj\n218 0 obj\n&lt;&lt;&quot;
  </code></pre>
  <p>But I got:</p>
  <pre><code>a = []
  </code></pre>
  <p>The problem is in the line <code>a = re.findall(r&quot;nendobj(.*?)W 3\.0&quot;,cadena)</code> but I don't realize where. I have tried many combinations with no success.</p>
  <p>I appreciate any comment.</p>
  <p>Regards</p>