Skip to content

Commit

Permalink
Merge pull request #143 from Sahillather002/URLinString
Browse files Browse the repository at this point in the history
URL finder in String
  • Loading branch information
Anjan50 authored Oct 21, 2023
2 parents a107f42 + 7971c2d commit d36c8f0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions URLinString.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import re

def find_urls(input_string):
# Define a regular expression pattern for matching URLs
url_pattern = r'https?://\S+|www\.\S+'

# Use re.findall to find all URLs in the input string
urls = re.findall(url_pattern, input_string)

return urls

# Example usage:
input_string = "This is a sample text with a URL: https://www.example.com and another URL: http://www.google.com"

urls_found = find_urls(input_string)

if urls_found:
print("URLs found in the input string:")
for url in urls_found:
print(url)
else:
print("No URLs found in the input string.")

0 comments on commit d36c8f0

Please sign in to comment.