+ 5
Youtube Link Finder - Python3 - ReGeX
Im trying to solve this problem, my code is below: import re inn = input() pattern = r"\b[=/](\w+)" match = re.findall(pattern,inn) if len(match): print(match[-1]) Test case #4 is failing and i dont know why, does someone know what i may be doing wrong? https://sololearn.com/coach/74/?ref=app
7 odpowiedzi
+ 5
Kike Salinas To be honest, I have a very poor knowledge about regex.
But let me try, I read your regex and it's super smart(I like it) but do you think that the youtube video ID only got alphabets, numeric and underscore symbol in them?
[ (\w+) - > Returns a match where the string contains any word characters (characters from a to Z, digits from 0-9, and the underscore _ character)] src: w3schools
Because along with reading your code, I also did a small research on YouTube video ID and I found that some ID also have got a dash(-), ampersand(&) and many others symbol.
(I may be wrong, sorry in advance) 😇
(by the way your code is working perfect with YouTube video ID having alphabets, numeric, underscore in them)
(and I'm not 100% though that this is the reason for test case 4 failure)
+ 3
Kike Salinas
I have recently started programming in Python.
Here is my code
link = list(input())
n = len(link)
id = []
for i in range(n - 10, n + 1):
id.append(link[i - 1])
print(''.join(id))
+ 2
Konstantin K read Terminal_Phantom solution, its a simpler way to do what you are doing (both are correct)
but in this case i was trying to find out a solution using ReGeX.
+ 1
rkk thx,
you were right!
i modified pattern as shown:
pattern = r"\b[/=]([^/=]+)"
and it works !
btw the problem said:
“Keep the video ID (the combination of letters and numbers at the end of the link) “
and i used \w cause in the examples of the problem there r also underline characters.
appreciate your help!
+ 1
My solution :
link = input()
print(link[-11:])
0
How about the second kind of the input?
You could first save your code here in Playground and check how it works for both different inputs.
0
#Can i have a vote for not using regex😂
#my code
link =input('')
if '=' in link :
lf1 = link.split('=')
d = lf1[-1]
print(d)
else:
lf2= link.split('/')
m = lf2[-1]
print(m)