title: How to return a regular expression match in PHP, instead of replacing
body: <p>I'm trying to extract the first src attribute of an image in a block of HTML text like this:</p>
  <pre><code>Lorem ipsum &lt;img src=&quot;http://example.com/img.jpg&quot; /&gt;consequat.
  </code></pre>
  <p>I have no problem creating the regular expression to match the src attribute, but how do I <strong>return</strong> the first matched src attribute, instead of <strong>replacing</strong> it?</p>
  <p>From pouring over the PHP manual, it seems like <a href="http://php.net/manual/en/function.preg-filter.php" rel="nofollow noreferrer">preg_filter()</a> would do the trick, but I can't rely on end users having a PHP version greater than 5.3.</p>
  <p>All the other PHP regular expression functions seem to be variations of preg_match(), returning a Boolean value, or preg_replace, which replaces the match with something. Is there a straightforward way to <strong>return</strong> a regular expression match in PHP?</p>