Detect the Domain Name

Sort by

recency

|

168 Discussions

|

  • + 0 comments
    import re
    
    n=int(input())
    htmls="\n".join(input() for _ in range(n))
    
    urls = re.findall(r"https?://[^\s\"'>?]+\.[a-z]{2,3}", htmls)
    domains=set()
    for url in urls:
        domain=re.sub(r"^https?://?","",url)
        domain=domain.split("/")[0]
        if "." in domain:
            domain=re.sub(r"^(www\d*\.)","",domain)
            domains.add(domain)
    print(";".join(sorted(domains)))
    
  • + 0 comments

    Detecting a domain name typically involves parsing the URL string to extract the domain using regex or built-in libraries in languages like Python or JavaScript. According to Wikipedia, a domain name identifies a realm of administrative autonomy within the Internet. In coding challenges, tools like urlparse or regex can simplify this process efficiently. I was practicing with real-world data like food service websites—checking out the Dairy queen menu helped simulate parsing dynamic URLs. It’s a fun way to blend real examples into coding logic while sharpening string manipulation skills.

  • + 0 comments
    html = sys.stdin.read()
    
    pattern = r'https?://(?:www\.|ww2\.)?([\w-]+\.[a-zA-Z0-9.-]+)'
    
    rs = set(re.findall(pattern,html))
    
    print(";".join(sorted(rs)))
    
  • + 0 comments

    import re import sys

    html= sys.stdin.read()

    pattern= r'https?://(?:www.|ww2.)?([a-zA-Z0-9-]+.?[a-zA-Z0-9-]+.[a-zA-Z].?[a-zA-Z])'

    matches=re.findall(pattern,html)

    output=sorted(set(url for url in matches))

    print(';'.join(output))

  • + 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)))