Question mark in regex not working as expected
<p>I want to match all text following <code>&gt;</code>, and optionally match links on the same line: </p>

<pre><code>preg_match('#(href="([^"]*))?.*&gt;(.*)#', '&lt;a href="world.html"&gt;Hello', $m);
print_r($m);
</code></pre>

<p>Input examples:</p>

<pre><code>&lt;a href="#catch-me" style="nice"&gt;Capture this text
This text should be ignored &lt;a href="#me-too"&gt;Other text to capture
&lt;p&gt;This line has no link, but should be matched anyway.
</code></pre>

<p>Expected result:</p>

<pre><code>[2] =&gt; world.html
[3] =&gt; Hello
</code></pre>

<p>Actual result:</p>

<pre><code>[2] =&gt; 
[3] =&gt; Hello
</code></pre>

<p>It works if I remove the question mark, but then the link obviously isn't optional anymore.</p>

<p>Why is this happening and how do I fix it?</p>