YouTube Link Finder
import re url = input() #https://www.youtube.com/watch?v=kbxkq_w51PM #https://youtu.be/KMBBjzp5hdc #extract video id like this #Input Format: #A string containing the URL to a YouTube video. The format of the string can be in "https://www.youtube.com/watch?v=kbxkq_w51PM" or the shortened "https://youtu.be/KMBBjzp5hdc" format. #Sample Input: #https://www.youtube.com/watch?v=RRW2aUSw5vU #Sample Output: #RRW2aUSw5vU pattern1 = r"https://www\.youtube\.com/watch\?v=(\w+)" pattern2 = r"https://youtu\.be/(\w+)" match1 =re.match(pattern1,url) match2= re.match(pattern2,url) if match1: print (match1.group(1)) else: print (match2.group(1)) This code has some bug which results in failed 4th test. Help me understand the problem!!