We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Regex
  3. Applications
  4. Detect the Domain Name
  5. Discussions

Detect the Domain Name

Problem
Submissions
Leaderboard
Discussions

Sort 113 Discussions, By:

votes

Please Login in order to post a comment

  • CalvinWestwood 6 years ago+ 0 comments

    Your expected output contains domain names not present in the input HTML code

    33|
    Permalink
  • wthit56 5 years ago+ 0 comments

    This is way too difficult without any spec on what constitutes a domain. It seems the expected output uses hidden rules for figuring out if a domain is "legal" or not.

    25|
    Permalink
  • jackbanh 5 years ago+ 0 comments

    This question needs a bit more polish. The instructions and test cases could use more clarity.

    1. "www." and "ww2." are expected to be filtered out but this instruction is easy to miss.
    2. In the real world, you cannot assume that "www.example.org" and "example.org" resolve to the same place
    3. The test case inputs are truncated so it's harder to debug
    4. There is no hint for which special characters are valid in a domain name
    22|
    Permalink
  • jobe_tr 5 years ago+ 0 comments

    Sigh. I spent far too long before realzing that the regex includes "http" or "https" in their regex.

    In normal html this is a valid link

    <a href="//google.com">Google.com</a>
    

    I was pulling those domains with my regex, but the solution does not.

    11|
    Permalink
  • mai_the_09 3 years ago+ 0 comments

    Java 8 Solution

    public class Solution {
    
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int n = Integer.parseInt(in.nextLine().trim());
    
            Pattern pa = Pattern.compile("http[s]?:\\/\\/(ww[w2]\\.)?(([a-zA-Z0-9\\-]+\\.)+([a-zA-Z\\-])+)");
    
            TreeSet<String> set = new TreeSet<>();
    
            while (n-- > 0) {
                String input = in.nextLine();
                Matcher ma = pa.matcher(input);
                while (ma.find()) set.add(ma.group(2));
            }
    
            for (String str : set) {
                System.out.print((str != set.last()) ? str + ";" : str);
            }
        }
    }
    
    9|
    Permalink
Load more conversations

Need Help?


View top submissions
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature