+ 2

Below is from Code Coach. 1/5 test running went failed,can anyone tell me where the bug is?

import re def extract(link): ret=re.match(r"^(https:\/\/www\.youtube\.com|https:\/\/youtu\.be)(\/watch\?v=|\/)([a-zA-Z0-9_]*)

quot;, link) if ret: print(ret.group(3)) li=input() extract(li)

2nd Jan 2020, 8:12 AM
kathy
12 odpowiedzi
+ 2
s=input() x=s.count("https://youtu.be/") if x==1: print(s[17:]) else: print(s[32:])
25th Mar 2020, 5:52 PM
S V S L N Surya Suhas Vaddhiparthy
S V S L N Surya Suhas Vaddhiparthy - avatar
+ 1
Hi, WhyFry. I checked your code, that’s a total different thinking and very smart by just spliting the string with relevent character.
2nd Jan 2020, 11:51 AM
kathy
+ 1
Hi, Rik , you have remind me, now it is working after I changed a-z,A-Z,etc in the brackets into ^\s.
2nd Jan 2020, 11:58 AM
kathy
+ 1
import re takeLink =list(input()) stri="".join(takeLink ) backSlash=0 if re.search("com",stri): for i in range(len(takeLink)): if takeLink[i]==r'=': break print("".join(takeLink[i+1:])) else: for i in range(len(takeLink )): if takeLink[i]==r'/': backSlash +=1 if backSlash == 3: break print ("".join(takeLink[i+1:]))
11th Nov 2020, 4:37 AM
MD FAYSAL MAHMUD
MD FAYSAL MAHMUD - avatar
+ 1
#This worked for me link = input("") for i in range(11): print(link[i-11])
25th Mar 2021, 3:16 AM
Mohamed Alaan
Mohamed Alaan - avatar
+ 1
link=input('') if len(link)>28: print(link[32:len(link)]) else: print(link[17:len(link)])
26th Oct 2021, 1:23 AM
youssef
youssef - avatar
0
Hi Kathy Nice code, smarter than I am so I am not sure if my next suggestion is valid. It appears to me that the link characters you have defined are a-z, A-Z,0-9. What if a link character is not contained within your definition?
2nd Jan 2020, 10:20 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
Hi, Rik. Below is the describtion from the code coach, it says the information to be extract is the at the end of the link, which is a combination of letters and nummbers. I have one test out of five failed. YouTube Link Finder You and your friends like to share YouTube links all throughout the day. You want to keep track of all the videos you watch in your own personal notepad, but you find that keeping the entire link is unnecessary. Keep the video ID (the combination of letters and numbers at the end of the link) in your notepad to slim down the URL. Task: Create a program that parses through a link, extracts and outputs the YouTube video ID. 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. Output Format: A string containing the extracted YouTube video id. Sample Input: https://www.youtube.com/watch?v=RRW2aUSw5vU Sample Output: RWW2aUSwvU
2nd Jan 2020, 11:10 AM
kathy
0
link = input() if '=' in link: x = link.split('=') print(x[1]) else: x = link.split('/') print(x[3])
26th Oct 2021, 6:07 PM
Vaibhav Gupta
Vaibhav Gupta - avatar
0
[Solved] I'm new here 🥱 import re txt = str(input()) pattern = r"watch" tr = re.search(pattern,txt) if tr: print(txt[32:]) else: print(txt[17:])
27th Jan 2022, 2:48 AM
Moussa Diallo
Moussa Diallo - avatar
0
#Swift #swift var a = (readLine() ?? "-").split(separator: "/") if a[1] == "www.youtube.com"{ var c = a[2].split(separator: "=") print(c[1]) }else if a[1] == "youtu.be"{ print(a.last!) }
12th Oct 2022, 9:19 AM
Artem Leschenko
Artem Leschenko - avatar