Regex: take string between <tag> and \n or </tag> : <p>I can't figure out where I'm wrong.</p>

<p>I have a pile of pages from where I need to get the content of the  tags and make it a file name.</p>

<p>My regex</p>

<pre><code>title2 = re.search(r'(&lt;title&gt;)(.+)(&lt;/title&gt;)', content)
filename_test = str(title2.group(2)+'.txt')
</code></pre>

<p>It works fine until it comes to a title like this:</p>

<pre><code>&lt;title&gt;Klaatu - barada nikto
&lt;/title&gt;
</code></pre>

<p>I've tried a lot of variants, none of them works.</p>

<p>Main idea is that something like this should have worked:</p>

<pre><code>title2 = re.search(r'(&lt;title&gt;)(.+)(\n|(&lt;/title&gt;))', content)
</code></pre>

<p>i.e. "stop when you come to new line <strong>or</strong> this tag"
But it doesn't.</p>
