Youtube Video ID From URL - Objective C

后端 未结 16 917
失恋的感觉
失恋的感觉 2020-12-22 23:23

I basically have a Youtube url as an NSString, but I need to extract the video id that is displayed in the url. I found many tutorials on how to do this in php or and other

16条回答
  •  情歌与酒
    2020-12-23 00:01

    Sorry - I don't have enough rep to add a comment to the chosen answer.

    After spending ages trying to find the correct syntax for the regex, I've come across this which has helped me. Hopefully it might help someone else!

    NSString *regexString = @"(?<=v(=|/))([-a-zA-Z0-9_]+)|(?<=youtu.be/)([-a-zA-Z0-9_]+)";
    

    Taken from here. This works for the following URL formats:

    • www.youtube.com/v/VIDEOID
    • www.youtube.com?v=VIDEOID
    • http://www.youtube.com/watch?v=KFPtWedl7wg&feature=youtu.be
    • http://www.youtube.com/watch?v=MkTD2Y4LXcM
    • youtu.be/KFPtWedl7wg_U923
    • http://www.youtube.com/watch?feature=player_detailpage&v=biVLGTAMC_U#t=31s

提交回复
热议问题