title: Oracle - need to extract text between given strings
body: <p>Example - need to extract everything between "Begin begin"  and "End end". I tried this way:</p>
  
  <pre><code>with phrases as (
    select 'stackoverflow is awesome. Begin beginHello, World!End end It has everything!' as phrase
      from dual
           )
  select regexp_replace(phrase
       , '([[:print:]]+Begin begin)([[:print:]]+)(End end[[:print:]]+)', '\2')
    from phrases
         ;
  </code></pre>
  
  <p>Result: Hello, World!</p>
  
  <p>However it fails if my text contains new line characters. Any tip how to fix this to allow extracting text containing also new lines?</p>
  
  <p>[edit]How does it fail:</p>
  
  <pre><code>with phrases as (
    select 'stackoverflow is awesome. Begin beginHello, 
    World!End end It has everything!' as phrase
      from dual
           )
  select regexp_replace(phrase
       , '([[:print:]]+Begin begin)([[:print:]]+)(End end[[:print:]]+)', '\2')
    from phrases
         ;
  </code></pre>
  
  <p>Result: </p>
  
  <blockquote>
    <p>stackoverflow is awesome. Begin beginHello,    World!End end It has
    everything!</p>
  </blockquote>
  
  <p>Should be:</p>
  
  <blockquote>
    <p>Hello,<br>
     World!</p>
  </blockquote>
  
  <p>[edit]</p>
  
  <p>Another issue. Let's see to this sample:</p>
  
  <pre><code>WITH phrases AS (
    SELECT 'stackoverflow is awesome. Begin beginHello,
   World!End end It has everything!End endTESTESTESTES' AS phrase
      FROM dual
  )
  SELECT REGEXP_REPLACE(phrase, '.+Begin begin(.+)End end.+', '\1', 1, 1, 'n')
    FROM phrases;
  </code></pre>
  
  <p>Result:</p>
  
  <blockquote>
    <p>Hello,<br>
    World!End end It has everything!</p>
  </blockquote>
  
  <p>So it matches last occurence of end string and this is not what I want. Subsgtring should be extreacted to first occurence of my label, so result should be:</p>
  
  <blockquote>
    <p>Hello,<br>
    World!</p>
  </blockquote>
  
  <p>Everything after first occurence of label string should be ignored. Any ideas?</p>