I'm looking for a way to use Regular Expression to scan through the following scenarios and return the youtube video ID of the specific video.
youtu.be/dQw4w9WgXcQ
www.youtube.com/watch?v=dQw4w9WgXcQ
https://www.youtube.com/watch?v=dQw4w9WgXcQ
https://www.youtube.com/watch?v=dQw4w9WgXcQ&index=2&list=PLsBI83Bzbnacim19bTUONClIGpT22Zfkw
All of the following cases should capture just dQw4w9WgXcQ
(the raw video ID)
Any idea of what regex I'd use to capture this? Keep in mind that youtube links can also include -
's and _
's, so \w+
will not always capture the video ID properly.
Thanks!