Android String to URL Convert getYoutubeId(String url)

Here you can find the source of getYoutubeId(String url)

Description

get Youtube Id

Declaration

public static String getYoutubeId(String url) 

Method Source Code

//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;
    }
}

Related

  1. isHttpUrl(String input)
  2. getDomain(String url)
  3. findUrl(StringBuilder sb)
  4. isImageUrl(String imgUrl)
  5. getBaseUrl(String pageUrl)
  6. preUrl(String url)
  7. TruncateUrlPage(String strURL)
  8. isValidUrl(String url)
  9. imageUrl_2_ImageName(String imageUrl)