We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
A quick tip on how to extract domain names from URLs and email addresses using Python:
import re
def extract_domain(input_string):
url_pattern = r'https?://(?:www\.)?([^/?]+)'
email_pattern = r'@([^@]+)'
url_match = re.search(url_pattern, input_string)
email_match = re.search(email_pattern, input_string)
if url_match:
return url_match.group(1)
elif email_match:
return email_match.group(1)
else:
return None
print(extract_domain('https://www.yellowduck.be')) # yellowduck.be
print(extract_domain('pieter@yellowduck.be')) # yellowduck.be
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.