getting the youtube id from a link

前端 未结 9 1168
清歌不尽
清歌不尽 2020-12-24 13:09

I got this code to get the youtube id from the links like www.youtube.com/watch?v=xxxxxxx

  URL youtubeURL = new URL(link);
  youtubeURL.getQuery();
         


        
9条回答
  •  既然无缘
    2020-12-24 13:33

    This doesn't use a regex but should still do the job.

    /**
     * Returns the video id of a YouTube watch link.
     */
    public static String getVideoId(String watchLink)
    {
        return watchLink.substring(watchLink.length() - 11);
    }
    

提交回复
热议问题