How do I get the YouTube video ID from a URL?

前端 未结 30 2412
北恋
北恋 2020-11-22 03:06

I want to get the v=id from YouTube’s URL with JavaScript (no jQuery, pure JavaScript).

Example YouTube URL formats

http://www.youtube.c

30条回答
  •  遥遥无期
    2020-11-22 03:28

    Simple regex if you have the full URL, keep it simple.

    results = url.match("v=([a-zA-Z0-9]+)&?")
    videoId = results[1] // watch you need.
    

提交回复
热议问题