Regular expression to extract URL from an HTML link

If you’re only looking for one: import re match = re.search(r’href=[\'”]?([^\'” >]+)’, s) if match: print(match.group(1)) If you have a long string, and want every instance of the pattern in it: import re urls = re.findall(r’href=[\'”]?([^\'” >]+)’, s) print(‘, ‘.join(urls)) Where s is the string that you’re looking for matches in. Quick explanation of the …

Read more