Computer >> Computer tutorials >  >> Programming >> Python

How to use Python Regular expression to extract URL from an HTML link?


The following code extracts the url from a html link using python regex

Example

import re
s = '''https://www.santa.com'''
match = re.search(r'href=[\'"]?([^\'" >]+)', s)
if match:
    print match.group(0)

Output

This gives the output

href="https://www.santa.com"