in reply to Stripping domain names from URLs

It sounds like you're suffering from poor definitions. First, you need to define what constitutes a domain name. Then, you need to define how to determine the exceptions. Then, and only then, can you code something reasonable to deal with it.

What I would do is take a long look at how you, personally, parse a domain name. That will give you the definition and exceptions. And, no, it's not s/^[^.]\.//, in case you're wondering.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

Replies are listed 'Best First'.
Re^2: Stripping domain names from URLs
by tachyon (Chancellor) on Sep 08, 2004 at 13:55 UTC

    Actually it is a reasonable description of the problem. Domain names exist in 3 basic forms:

    domain.TLD where TLD (Top Level Domain) is com, net, org etc domain.ccTLD where ccTLD (Country Code TLD) is say .de domain.SLD.ccTLD where SLD.ccTLD (Second Level Domain ccTLD) is com.au +, co.uk, etc # additionally we may have as a prefix www.domain.... subdomain.domain..... subsubdomain.subdomain.domain.....

    So the task is how to extract the DOMAIN component +/- subdomains. The issue is that if you split on the . then the DOMAIN component has an index of either 0,1,2...N if you look from the left or -3 or -2 if you look from the right. See my post below for a heuristic that deals with most of the weirdness. The most annoying freature is that domian.ccTLD exists. If not all you would need to do is pop 1 element off if it was a TLD and 2 if it was a ccTLD. Alas that would be too easy!

    cheers

    tachyon

      I understand that there is a precise problem statement for the issue the OP was dealing with, as you have stated. What I was getting at was the the OP hadn't found that precise statement.

      This is actually a more fundamental concept issue with our field in general - most programmers don't realize that development is at least 80% thinking and no more than 20% typing. I was reading some onLamp.com articles on FreeBSD installations and one author kept saying that installs were "99% preparation and 1% installation". I think that this is extremely appropriate to programming and computers in general. Most programming is actually quite easy - even trivial ... once you have figured out the problem you're trying to solve.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      I shouldn't have to say this, but any code, unless otherwise stated, is untested