In this case, we are using the re module in Python, here we take a string and check if the string contains a URL ant. If the url is in the string, display. We are using findall () method to solve this problem.
Step 1: given string as input. Step 2: findall () function is return all non-overlapping matches of pattern in string and in this function the string is scanned left to right and matches are returned in the order found.
# Program to find the URL from an input string import re def url (str): # findall () has been used # with valid conditions for urls in string ur = re.findall ('http [s]?: // (?: [a-zA-Z] | [0-9] | [$ -_ @ . +] | [! * (),] | (?:% [0-9a-fA-F] [0-9a-fA-F])) + ', str) return ur # Driver Code str =' https : //auth.mywebsite.org / user / python program / http: // www.mywebsite.org / 'print (" Url is :: ", url (str))
Url is :: ['https://auth.mywebsite.org / user / python program / http: // www.mywebsite.org /' ]