How do I get the YouTube video ID from a URL?

I made an enhancement to Regex provided by “jeffreypriebe” because he needed a kind of YouTube URL is the URL of the videos when they are looking through a channel.

Well no but this is the function that I have armed.

<script type="text/javascript">
function youtube_parser(url){
    var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
    var match = url.match(regExp);
    return (match&&match[7].length==11)? match[7] : false;
}
</script>

These are the types of URLs supported

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


Can be found in [http://web.archive.org/web/20160926134334/]
http://lasnv.net/foro/839/Javascript_parsear_URL_de_YouTube

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)