Files
CyberPanel/plogical/test.py

22 lines
533 B
Python
Raw Normal View History

2023-09-24 17:44:30 +04:00
import re
def extract_domain_parts(domain):
# Use a regular expression to extract the domain parts
pattern = r'(?:\w+\.)?(\w+)\.(\w+)'
match = re.match(pattern, domain)
if match:
subdomain = match.group(1)
top_level_domain = match.group(2)
return subdomain, top_level_domain
else:
return None, None
# Example usage
domain = "sub.example.ae"
subdomain, top_level_domain = extract_domain_parts(domain)
print("Subdomain:", subdomain)
print("Top-Level Domain:", top_level_domain)