1import re
2
3url = '<p>Hello World</p><a href="http://example.com">More Examples</a><a href="http://example2.com">Even More Examples</a>'
4
5urls = re.findall('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', url)
6
7>>> print urls
8['http://example.com', 'http://example2.com']
9
1import re
2
3with open("path\url_example.txt") as file:
4 for line in file:
5 urls = re.findall('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', line)
6 print(urls)
7
1Don't try to make your own regular expression for matching URLs, use someone else's who has already solved such problems, like this one.