-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from Sahillather002/URLinString
URL finder in String
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |