- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to check for URL in a string
In this case we use re module in Python, Here we accept a string and check if the string contains ant URL in it. If the URL is present in the string then display. We use 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/']
- C# program to check for URL in a String
- Java program to check for URL in a String
- How to check if a string is a valid URL in Golang?
- How to check URL for 404 using Selenium WebDriver?
- C# Program to check a string for whitespace characters or null
- C# program to check for a string that contains all vowels
- Program to check a string is palindrome or not in Python
- Program to check typed string is for writing target string in stuck keyboard keys or not in Python
- Python Program to check if a substring is present in a given string.
- Python program to check if a string is palindrome or not
- Python program to check if a string contains all unique characters
- Python program to check if a given string is number Palindrome
- Python program to check if a string contains any unique character
- Program to check if a string contains any special character in Python
- Program to check string contains consecutively descending string or not in Python