The following code is used to get Youtube video ids in order to get a thumbnail image.
What is the reasoning behind the first regular expression and what is it doing exactly? It appears to be returning at least two results. Also, could the two be combined?
else if(url.match("youtube.com/")){
var vid;
var results;
//http://www.youtube.com/watch?v=GItD10Joaa0
results = url.match("[\\?&]v=([^&#]*)");
vid = ( results === null ) ? url : results[1];
return "http://img.youtube.com/vi/"+vid+"/2.jpg";
} else if( url.match("youtu.be/") ) {
var vid;
var results;
// http://youtu.be/5uxd-521uus?hd=1
// results = url.match("[^http://youtu.be/](.*)[^?hd=1]");
// Corrected
results = url.match(""^http://youtu.be/(.*)(?=hd=1)");
//alert(results[0]);
vid = ( results === null ) ? url : results[0];
return "http://img.youtube.com/vi/"+vid+"/2.jpg";
}