regexp='^http:\/\/(?:www\.)?youtube.com\/watch\?(?=.*v=\w+)(?!\S+http:\/\/)(?:\S*)$'
fURL()
{
echo -n "Enter the YouTube URL to download: "
read URL
if [ "$URL" != "$regexp" ]; then
echo "${red}Invalid YouTube URL!${normal}"
fURL;
fi
}
我用http://www.youtube.com/watch?v=tfTWHbtv_-Y测试我的脚本- 但它仍然说它无效。
我尝试修改代码:
echo $URL | grep "^http:\/\/(?:www\.)?youtube.com\/watch\?(?=[^?]*v=\w+)(?:[^\s?]+)?$"
if [ $? -ne "0" ]; then
echo "${red}Invalid YouTube URL!${normal}"
fURL;
else
echo URL is good.
有人可以帮忙吗?谢谢!