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();
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); }