Reputation: 151
I am trying to filter out just links from an input that the user provides. However currently I am having trouble with Python's findall as it does not return any results.
There might be a mistake in the regular expression itself since that's not a part of my actual code and I copied that in another post but I tried to check it with my current understanding of regular expressions and didn't see an obvious issue.
These are the example links that I am trying to filter :
https://ncs.io/symbolism, https://soundcloud.com/nocopyrightsounds/electro-light-symbolism-ncs-release, https://www.youtube.com/watch?v=__CRWE-L45k, https://www.deezer.com/track/93333734?app_id=140685, https://open.spotify.com/album/1BxVIZuG2N1ReBB0T5nVTr?highlight=spotify:track:2zVJlAEB0ublkqJMIn43AE
To get the results I am using a simple function which should directly return the result :
def get_urls():
# Gets urls from the provided string
urls = input("Stream urls: ")
urls = findall(r'(https?://[^\s]+)', urls)
return urls
Which I then properly call :
if __name__ == '__main__':
print(get_urls())
I am importing just findall from re since that's the only part I use :
from re import findall
There isn't really much that can break in this small code and I myself am extremely confused as to where I screwed up. If you see me mistake please help me out! Thanks for any help with this!
Upvotes: 0
Views: 132
Reputation: 1205
It works for me
from re import findall
def get_urls():
# Gets urls from the provided string
urls = input("Stream urls: ")
urls = findall(r'(https?://[^\s,]+)', urls)
return urls
if __name__ == '__main__':
print(get_urls())
Upvotes: 1