title: Grep regex - select text between tag BUT text contains string AND stop at first end-tag
body: <p>The command I use:</p>
  
  <pre><code>grep -oP '(?s)opentag.*?myString.*?closetag' myFile
  </code></pre>
  
  <p>This is working fine when the text 'myString' is found between the tags.
   For this case :</p>
  
  <pre><code>opentag
    myString
  closetag
  </code></pre>
  
  <p>the result is:</p>
  
  <pre><code>myString
  </code></pre>
  
  <p>But when 'myString' is not found, grep will consider the next 'closetag'. Exemple :</p>
  
  <pre><code>opentag
  closetag
    myString
  closetag
  </code></pre>
  
  <p>the result is:</p>
  
  <pre><code>closetag
    myString
  </code></pre>
  
  <p>Is there any way to stop the parsing at the first 'closetab' read ?
  In this case there won't be any results.</p>
  
  <p>I can do it by coding a parser but not the time nor the motivation.</p>
  
  <p>Thank you for your help ! </p>