 <p>I would first fetch the title tag and then process the title further. The other answers contain perfectly valid solutions for this task.</p> <h2>Some further notes:</h2> <ul> <li>Please use DOMDocument for such things, since it is much safer (your regular expression might break on some specific HTML pages)</li> <li><p><strong>Please use the non-greedy version of <code>.*</code>: <code>.*?</code></strong>, otherwise you will run into funny things like:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;a&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;title&gt;test&lt;/title&gt; &lt;!-- not allowed in HTML, but since when does the web pages online actually care about that? --&gt; &lt;/body&gt; &lt;/html&gt; </code></pre></li> </ul> <p>You will now match everything between <code>&lt;title&gt;a&lt;/title&gt;...</code> up to <code>&lt;title&gt;test&lt;/title&gt;</code>, including everything in between.</p>