Member-only story
Python — Extracting URLs from strings
As a Python developer, we have to accomplished a lot of jobs such as data cleansing from a file or texts before processing the other business operations.
For an example, you have a raw data text file or text string and you have to read some specific data like URLs by to performing the actual Regular Expression matching.
What is a Regular Expression and which module is used in Python?
Regular expression is a sequence of special character(s) mainly used to find and replace patterns in a string or file, using a specialized syntax held in a pattern.
The Python module re provides full support for Perl-like regular expressions in Python. The re module raises the exception re.error if an error occurs while compiling or using a regular expression.
pandas is a Python package providing fast, powerful, flexible and easy to use open source data analysis and manipulation tool, built on top of the Python programming language.
Example —
# Python program to extract URLs from the String By Regular Expression.
# Importing module required for regular expressions
import re
import pandas as pd
# Example string
text = “To learn more, please follow us — http://www.sql-datatools.com To Learn more, please visit our YouTube channel at — http://www.youtube.com/c/Sql-datatools To Learn more…