
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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 = '''http://www.santa.com''' match = re.search(r'href=[\'"]?([^\'" >]+)', s) if match: print match.group(0)
Output
This gives the output
href="http://www.santa.com"
- Related Articles
- How to extract numbers from text using Python regular expression?
- How to extract date from text using Python regular expression?
- How to extract floating number from text using Python regular expression?
- How to extract email id from text using Python regular expression?
- How to use wildcard in Python regular expression?
- How to use range in Python regular expression?
- How to use variables in Python regular expression?
- How to write a Python regular expression to use re.findall()?
- How to use special characters in Python Regular Expression?
- How to link pages using absolute URL in HTML?
- How to link pages using relative URL in HTML?
- How to validate a URL using regular expression in C#?
- How to use an image as a link in HTML?
- How to extract each (English) word from a string using regular expression in Java?
- How to extract data from a string with Python Regular Expressions?

Advertisements