I found a great bit of code here to extract the ID from a youtube URL in PHP
.
I'm now having syntax issues converting this regex to Perl
.
preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $link, $matches);
This matches the following versions, extracting this portion of the URL: g6QrR5Uakeg
youtube.com/v/g6QrR5Uakeg
youtube.com/vi/g6QrR5Uakeg
youtube.com/?v=g6QrR5Uakeg
youtube.com/?vi=g6QrR5Uakeg
youtube.com/watch?v=g6QrR5Uakeg
youtube.com/watch?vi=g6QrR5Uakeg
youtu.be/g6QrR5Uakeg
www.youtube.com/v/g6QrR5Uakeg?feature=autoshare&version=3&autohide=1&autoplay=1