title: Regex to match links but not images or youtube videos
body: <p>I need to match any valid links separately from links to images and youtube videos. I'd like to put anchor tags around regular links but img and iframe tags around images and youtube videos respectively.</p>
  
  <p>Here's my code</p>
  
  <pre><code>$str = "some stuff with links"
  
      $output = preg_replace('#(http://([^\s]*)\.(jpg|gif|png))#', 
                      '&lt;img src="$1" alt="" width="" height="" /&gt;', $str);
  
  
  
      $output = preg_replace('#(http://([^\s]*)youtube\.com/watch\?v=([^\s]*))#', 
                    '&lt;iframe width="420" height="315" src="http://www.youtube.com/embed/$3" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;', $output);
  
      var_dump($output);
  </code></pre>
  
  <p>This ignores regular links, how do I modify it to detect links but not the other two? Is there a simpler way?</p>
  
  <p>Thanks</p>