Possible Duplicate:
Regex to parse youtube yid
your probably thinking not another one, but here i have a jquery regex which i find it works fine on the majority of urls accpet one example at bottom:
http://www.youtube.com/watch?v=0zM3nApSvMg&feature=feedrec_grec_index
http://www.youtube.com/user/IngridMichaelsonVEVO#p/a/u/1/QdK8U-VIH_o
https://youtube.com/watch?v=0zM3nApSvMg%3Ffs%3D1%26amp%3Bhl%3Den_US%26amp%3Brel%3D0
https://youtube.com/watch?v=0zM3nApSvMg%3Frel%3D0
the regex
/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/
but this cannot extract the id from the url below (in this example the id is pa14VNsdSYM)
http://www.youtube.com/watch?feature=endscreen&NR=1&v=pa14VNsdSYM
how can using the regex can i extract the id from urls such as the one above.
The youtube url id always contains 11 characters numbers underscores and/or dashes. This is the regexp i’ve used and haven’t had issues with:
Edit: this solution doesn’t actually work 100%, the first and second url’s will have issues because the regexp matches text that isn’t the vid id.
Edit2: try this one:
http://jsfiddle.net/HfqmE/1/