title: Regex to extract domain and video id from youtube/vimeo url
body: <p>I am copying a function that will take a youtube/vimeo url and return what site the video came from (vimeo/yt) as well as the video id.</p>
  
  <p>Here's what I have so far: <a href="http://jsfiddle.net/csjwf/181/" rel="noreferrer">http://jsfiddle.net/csjwf/181/</a></p>
  
  <pre><code>&lt;strong&gt;Result:&lt;/strong&gt;
  &lt;div id="result"&gt;&lt;/div&gt;
  </code></pre>
  
  
  
  <pre><code>function parseVideoURL(url) {
  
      url.match(/^http:\/\/(?:.*?)\.?(youtube|vimeo)\.com\/(watch\?[^#]*v=(\w+)|(\d+)).+$/);
      return {
          provider : RegExp.$1,
          id : RegExp.$1 == 'vimeo' ? RegExp.$2 : RegExp.$3
      }
  }
  
  var result = document.getElementById("result");
  var video = parseVideoURL("http://www.youtube.com/watch?v=PQLnmdOthmA&amp;feature=feedrec_grec_index");
  result.innerHTML = "Provider: " + video.provider + "&lt;br&gt;ID: " + video.id;
  
  var video = parseVideoURL("http://vimeo.com/22080133");
  
  result.innerHTML += "&lt;br&gt;--&lt;br&gt;Provider: " + video.provider + "&lt;br&gt;ID: " + video.id;
  </code></pre>
  
  <p>Output:</p>
  
  <pre>Result:
  Provider: youtube
  ID: PQLnmdOthmA
  --
  Provider: vimeo
  ID: 2208013</pre>
  
  <p>However, notice how for vimeo vids, if the url ends in the ID, the last number is always cut off. If you add a slash to the end of the vimeo url the id is pulled fully. </p>