Regex to extract titles from the text
<p>Can anyone help with the regex to extract the text phrases after 'Title:' from the following text: (have just bolded the text to clearly depict the portion to be extracted)</p>

<pre>Title: <b>Anorectal Fistula (Fistula-in-Ano)</b> Procedure Code(s): 



Effective date: 7/1/07

Title:

<b>2003247</b> 

or previous effective dates) 



Title: 

<b>ST2 Assay for Chronic Heart Failure</b> 

Description/Background 

Heart Failure 

HF is one among many cardiovascular diseases that comprises a major cause of morbidity 
and mortality worldwide. The term âheart failureâ (HF) refers to a complex clinical syndrome .</pre>

<p>I am using the regex: <code>(?:Title: \n+(.*))|(?:Title:\n+(.*))|(?&lt;=Title: )(.*)(?=Procedure)</code></p>

<p>However, it doesn't seem to capture the terms correctly! I am using Python 2.7.12</p>

<p>I suggest using</p>

<pre><code> Title:\s*(.*?)\s*Procedure|Title:\s*(.*)
</code></pre>

<p>See the <a href="https://regex101.com/r/a8DXbK/1" rel="nofollow">regex demo</a>.</p>

<p><em>Details</em>:</p>

<ul>
<li><code>Title:</code> - literal text <code>Title:</code></li>
<li><code>\s*</code> - 0+ whitespaces</li>
<li><code>(.*?)</code> - Group 1: any 0+ chars other than linebreak symbols as few as possible up to the first</li>
<li><code>\s*Procedure</code> - 0+ whitespaces + the string <code>Procedure</code></li>
<li><code>|</code> - or</li>
<li><code>Title:\s*</code> - <code>Title:</code> string + 0+ whitespaces</li>
<li><code>(.*)</code> - Group 2: zero or more any chars other than linebreak symbols as many as possible (the rest of the line).</li>
</ul>

<p><a href="http://ideone.com/QJiZjR" rel="nofollow">Python code</a>:</p>

<pre><code>import re
regex = r"Title:\s*(.*?)\s*Procedure|Title:\s*(.*)"
test_str = ("Title: Anorectal Fistula (Fistula-in-Ano) Procedure Code(s):\n\n"
    "Effective date: 7/1/07\n\n"
    "Title:\n\n"
    "2003247\n\n"
    "or previous effective dates)\n\n"
    "Title:\n\n"
    "ST2 Assay for Chronic Heart Failure\n\n"
    "Description/Background\n\n"
    "Heart Failure\n\n"
    "HF is one among many cardiovascular diseases that comprises a major cause of morbidity and mortality worldwide. The term âheart failureâ (HF) refers to a complex clinical syndrome .")
res = []
for m in re.finditer(regex, test_str):
    if m.group(1):
        res.append(m.group(1))
    else:
        res.append(m.group(2))
print(res)
# =&gt; ['Anorectal Fistula (Fistula-in-Ano)', '2003247', 'ST2 Assay for Chronic Heart Failure']
</code></pre>

python regex python-2.7 text-extraction