Detect the Domain Name – HackerRank Solution

In this post, we will solve Detect the Domain Name HackerRank Solution. This problem (Detect the Domain Name) is a part of HackerRank Regex series.

Solution – Detect the Domain Name – HackerRank Solution

Python

import re
pattern = '(http|https)\\://(www.|ww2.|)([a-zA-Z0-9\\-\\.]+)(\\.[a-zA-Z]+)(/\\S*)?'
regex = re.compile(pattern)
s = set()
for i in range(int(input())):
    string = input()
    iterator = regex.finditer(string)
    if iterator:
        for match in iterator:
            s.add(match.group(3)+match.group(4))
print(';'.join(t for t in sorted(s)))

Note: This problem (Detect the Domain Name) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *