I'm looking to extract only the video id string from a column of youtube links.
The stringr function I'm currently using is this:
str_extract(data$link, "\\b[^=]+$")
This works for most standard youtube links with the id at the end of the url appearing after an = sign i.e.
youtube.com/watch?v=kFF0v0FQzEI
However not all links follow this pattern, examples:
youtube.com/v/kFF0v0FQzEI
youtube.com/vi/kFF0v0FQzEI
youtu.be/kFF0v0FQzEI
www.youtube.com/v/kFF0v0FQzEI?feature=autoshare&version=3&autohide=1&autoplay=1
www.youtube.com/watch?v=kFF0v0FQzEI&list=PLuV2ACKGzAMsG-pem75yNYhBvXZcl-mj_&index=1
So could anyone help me out with an R regex pattern to extract the id (kFF0v0FQzEI in this case) in all the examples above?
I've seen examples of regex patterns used in other languages to do this but I'm unsure how to convert to R compliance.
Thanks!