java to validate Youtube url using regular expression

Through java regular expression we can validate Youtube url of channel

Example of java programme to validate Youtube url using regular expression

Regular expression of Youtube channel

^(https\:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.mavenproject1;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author ASUS
 */
public class Helloworld {
 private static String facebookurl="";
     private static boolean Youtube(String url){
        Pattern p = Pattern.compile("^(https\\:\\/\\/)?(www\\.)?(youtube\\.com|youtu\\.?be)\\/.+$");
        Matcher m=p.matcher(url);
        boolean matches = m.matches();
        return matches;
    }
   public static void main(String[] args){

       System.out.println("result of youtube url"+ Youtube(facebookurl));
   } 
}

Leave a Comment