So I've got a strange issue with my youtube plugin, it doesn't seem to handle parameters after the youtube ID very well.
I've got a var that looks like this:
id = $el.data('youtube-id')
Which is parsed via the following regex
var regularUrl = /<a href="(?:https?:\/\/)?(?:www\.)?(?:youtube\.com)\/(?:watch\?v=)([\w\-_]+)?&([\w\-_]+)">.+<\/a>/g;
var shortUrl = /<a href="(?:https?:\/\/)?(?:www\.)?(?:youtu\.be)\/([\w\-_]+)">.+<\/a>/g;
var embedUrl = /<a href="(?:https?:\/\/)?(?:www\.)youtube.com\/embed\/([\w\-_]+)">.+<\/a>/;
Except it doesn't just put the ID in, it also includes all of the parameters that a user may add afterwards, like start times etc. Which breaks, because the ID becomes tGZlwK2qTCI&t=3m20s
which isn't a valid video ID. Normally this would only be a problem for the thumbnail that I fetch, but I append &autoplay to the URL here:
src="//www.youtube.com/embed/' + id + '?autoplay=1"
I assume it's something up with my regex, I would like $1 to be just the video ID (11 characters), and everything after that to become a part of $2 so I can parse the parameters back in afterwards.
Basically what I'm after is the youtube URL looking like
src="//www.youtube.com/embed/' + id + '?autoplay=1` + parameters + `"
So $1
would be the 11 character youtube ID, and $2
would be all other parameters after that ID.