title: Regex for YouTube ID
body: <p>I've looked all over and I've seen many ways to parse the video ID off a URL for youtube, however, none of them have matched all the various formats the YouTube url could be in.  I've tried messing with regex presented in the previous posts, but nothing seemed to work.</p>
  
  <p>The closest post I found that covered all the various URL formats was this one: <a href="https://stackoverflow.com/questions/5830387/php-regex-find-all-youtube-video-ids-in-string/6901180#6901180">How do I find all YouTube video ids in a string using a regex?</a></p>
  
  <p>However, this does not work for:
  <a href="http://www.youtube.com/sandalsResorts#p/c/54B8C800269D7C1B/0/FJUvudQsKCM" rel="noreferrer">http://www.youtube.com/sandalsResorts#p/c/54B8C800269D7C1B/0/FJUvudQsKCM</a></p>
  
  <p>I'm doing this in Javascript.  Can someone help?!</p>
  
  <p>Thanx in advance.</p>
  
  <p>Current URL formats and script I am using:</p>
  
  <pre><code>var url = "http://www.youtube.com/sandalsResorts#p/c/54B8C800269D7C1B/0/FJUvudQsKCM";
  //var url = "http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo";
  //var url = "http://youtu.be/NLqAF9hrVbY";
  //var url = "http://www.youtube.com/embed/NLqAF9hrVbY";
  //var url = "https://www.youtube.com/embed/NLqAF9hrVbY";
  //var url = "http://www.youtube.com/v/NLqAF9hrVbY?fs=1&amp;hl=en_US";
  //var url = "http://www.youtube.com/watch?v=NLqAF9hrVbY";
  //var url = "http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo";
  //var url = "http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I";
  //var url = "http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo";
  //var url = "http://www.youtube.com/watch?v=JYArUl0TzhA&amp;feature=featured";
  
  var videoID = url.match(/(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/user\/\S+|\/ytscreeningroom\?v=))([\w\-]{10,12})\b/)[1];
  alert(videoID);
  </code></pre>