YouTube Link Finder | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

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!!

5th Jan 2021, 9:46 AM
CHANDAN ROY
CHANDAN ROY - avatar
3 Answers
+ 1
\w is [0-9A-Za-z_] But YouTube links have a character \w doesn't include, -
5th Jan 2021, 10:42 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
can u give the test cases
5th Jan 2021, 9:49 AM
durian
durian - avatar
0
Lily Mea This is a codecoach challenge. Test cases are hidden.
5th Jan 2021, 9:52 AM
CHANDAN ROY
CHANDAN ROY - avatar