title: PHP preg_match_all regex to extract only number in string
body: <p>I can't seem to figure out the proper regular expression for extracting just specific numbers from a string. I have an HTML string that has various img tags in it. There are a bunch of img tags in the HTML that I want to extract a portion of the value from. They follow this format:</p>
  
  <pre><code>&lt;img src="http://domain.com/images/59.jpg" class="something" /&gt;
  &lt;img src="http://domain.com/images/549.jpg" class="something" /&gt;
  &lt;img src="http://domain.com/images/1249.jpg" class="something" /&gt;
  &lt;img src="http://domain.com/images/6.jpg" class="something" /&gt;
  </code></pre>
  
  <p>So, varying lengths of numbers before what 'usually' is a .jpg (it may be a .gif, .png, or something else too). I want to only extract the number from that string. </p>
  
  <p>The 2nd part of this is that I want to use that number to look up an entry in a database and grab the alt/title tag for that specific id of image. Lastly, I want to add that returned database value into the string and throw it back into the HTML string. </p>
  
  <p>Any thoughts on how to proceed with it would be great...</p>
  
  <p>Thus far, I've tried:</p>
  
  <pre><code>$pattern = '/img src="http://domain.com/images/[0-9]+\/.jpg';
  preg_match_all($pattern, $body, $matches);
  var_dump($matches);
  </code></pre>