Detect the Domain Name

  • + 0 comments
    import re
    import sys
    
    domain_pattern = re.compile(r'https?://(?:www\.|ww2\.)?([a-zA-Z0-9\-]+\.[a-zA-Z0-9.\-]+)[^a-zA-Z0-9.\-]')
    
    input_stream = sys.stdin
    
    unique_domains = set()
    
    n = int(input_stream.readline().strip())
    
    for _ in range(n):
        line = input_stream.readline().strip()
        for match in domain_pattern.findall(line):
            unique_domains.add(match)
    
    print(';'.join(sorted(unique_domains)))