laravel if valid youtube link url
$url = "www.youtube.com/cCnrX1w5luM";
$regex_pattern = "/(youtube.com|youtu.be)\/(watch)?(\?v=)?(\S+)?/";
$match;
if (
filter_var($url, FILTER_VALIDATE_URL)
&& preg_match($regex_pattern, $url, $match)
) {
echo "Youtube video id is: ".$match[4];
} else {
echo "Sorry, not a youtube URL";
}