I am trying to find a clean way to extract all urls in a text string.
After an extensive search, i have found many posts suggesting using regular expressions to do t
output = [x for x in input().split() if x.startswith('http://') or x.startswith('https://') or x.startswith('ftp://')]
print(output)
your example: http://ideone.com/wys57x
After all you can also cut last character in elements of list if it is not a letter.
EDIT:
output = [x for x in input().split() if x.startswith('http://') or x.startswith('https://') or x.startswith('ftp://')]
newOutput = []
for link in output:
copy = link
while not copy[-1].isalpha():
copy = copy[:-1]
newOutput.append(copy)
print(newOutput)
Your example: http://ideone.com/gHRQ8w