title: PHP: Regular Expression to get a URL from a string
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/951198/identifying-if-a-url-is-present-in-a-string">Identifying if a URL is present in a string</a><br>
    <a href="https://stackoverflow.com/questions/1038284/php-parse-links-emails">Php parse links/emails</a>  </p>
  </blockquote>
  
  
  
  <p>I'm working on some PHP code which takes input from various sources and needs to find the URLs and save them somewhere. The kind of input that needs to be handled is as follows:</p>
  
  <pre><code>http://www.youtube.com/watch?v=IY2j_GPIqRA
  Try google: http://google.com! (note exclamation mark is not part of the URL)
  Is http://somesite.com/ down for anyone else?
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>http://www.youtube.com/watch?v=IY2j_GPIqRA
  http://google.com
  http://somesite.com/
  </code></pre>
  
  <p>I've already borrowed one regular expression from the internet which works, but unfortunately wipes the query string out - not good!</p>
  
  <p>Any help putting together a regular expression, or perhaps another solution to this problem, would be appreciated.</p>