title: javascript regex to find image urls in string
body: <p>I'm using a Javascript regEx to parse a database field for image urls and format them for output - so far, I have been using </p>
  
  <pre><code>input = input.replace(/(https?:\/\/.*?\.(?:png|jpe?g|gif)(.*))(\w|$)/ig, "&lt;br&gt;&lt;img style='max-width:100%;overflow:hidden;' src='$1'&gt;");
  </code></pre>
  
  <p>and its been serving me well.  All png, jpe?g and gif references get replaced by IMG tags and images show in the output stream as intended.</p>
  
  <p>However, I've been thrown a loop.</p>
  
  <p>I've noticed some urls (notably those from Facebook CDN - though I supposed others could also be doing this as well) have appended a whole pile of "stuff" after the image type ...  stuff that if not present results in the files not being available, and a missing image icon gets produced.  For example, this is a valid picture url from fbcdn.net:</p>
  
  <pre><code>https://scontent-lga1-1.xx.fbcdn.net/hphotos-xtf1/v/t1.0-9/11147160_10156300867440377_5455334309678688318_n.jpg?oh=916e68ac2c908bbe15961825c373d6bc&amp;oe=5606B6F4
  </code></pre>
  
  <p>Can someone suggest a change/improvement to the regEx that would pick up the extra trailing characters?  Or is another method of attack necessary </p>
  
  <p>(I personally like the global regEx as I can nail all of the instances in the stream at once... having to manually parse the stream is not something I would look forward to...)</p>
  
  <p><strong>Update:</strong> I understand there is some ambiguity in the request - hopefully this will clarify.  </p>
  
  <p>I need to pull out any image url - regardless of the "stuff" after the image extention.   It could be the first item in the text string, or the last, or embedded somewhere in the middle.</p>
  
  <p>The processing is done in Javascript.  I am currently using this as my validity test.  All images within it are valid urls pulled from Google image search.</p>
  
  <pre><code>http://well-being.esdc.gc.ca/misme-iowb/auto/diagramme-chart/stg2/c_4_21_6_1_eng.png?20150508104424447 This is arbitrary text https://scontent-lga1-1.xx.fbcdn.net/hphotos-xtf1/v/t1.0-9/11147160_10156300867440377_5455334309678688318_n.jpg?oh=916e68ac2c908bbe15961825c373d6bc&amp;oe=5606B6F4 this is arbitrary text
  
  http://lh6.ggpht.com/-1Rua79J-EDo/TwuyZkHwcmI/AAAAAAAADvA/ENfg1TeayvU/type_catalog_error_thumb%25255B1%25255D.jpg?imgmax=800 this is arbitrary text http://image.slidesharecdn.com/top5thingstodoafteranaccident-140826163850-phpapp02/95/top-five-things-to-do-after-any-type-of-accident-causing-injury-1-638.jpg?cb=1409089267
  </code></pre>
  
  <p>Hopefully this sheds sufficient light into the types of variations I may encounter  (The only one I know for sure is the FBCDN - I'm basing the others on knowledge of what else I've seen out there... so a generalized solution is needed, not one specific to FBCDN).</p>
  
  <p>Thank you to all that offer suggestions... </p>