Here you can find the source of getYoutubeId(String url)
public static String getYoutubeId(String url)
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String getYoutubeId(String url) { String pattern = "https?:\\/\\/(?:[0-9A-Z-]+\\.)?(?:youtu\\.be\\/|youtube\\.com\\S*[^\\w\\-\\s])([\\w\\-]{11})(?=[^\\w\\-]|$)(?![?=&+%\\w]*(?:['\"][^<>]*>|<\\/a>))[?=&+%\\w]*"; Pattern compiledPattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE); Matcher matcher = compiledPattern.matcher(url); if (matcher.find()) { return matcher.group(1); }/*from w w w. j a v a2s. c om*/ return null; } }