Regex to extract URLs from href attribute in HTML with Python

Viewed 158910

Possible Duplicate: What is the best regular expression to check if a string is a valid URL?

Considering a string as follows:

string = "<p>Hello World</p><a href="http://example.com">More Examples</a><a href="http://2.example">Even More Examples</a>"

How could I, with Python, extract the URLs, inside the anchor tag's href? Something like:

>>> url = getURLs(string)
>>> url
['http://example.com', 'http://2.example']
2 Answers
Related