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();
That pattern worked for me:
"http(?:s?)://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)([\w\-]+)(&(amp;)?[\w\?=]*)?"
source: Regular expression for youtube links