On Tue, 2003-09-02 at 12:54, perl wrote:
> Please help me parse this www.mydomain.com to just mydomain.com 
> 
> Below are some scenarios in which all I want is the last two values, 
> mydomain.com : 
> 
> mydomain.com = mydomain.com
> www.yourdomain.com = yourdomain.com
> www.station.fire.org = fire.org 
> 
> results in just the base domain. 
> 
> thanks 

I noticed a regex that someone posted so I'll offer up the same solution
with a split, and play a bit of devils advocate on this idea in and of
it's self...

my $domain = 'www.station.fire.org';
my($part1, $part2) = (split(/\./, $domain))[-2, -1];
my $basedomain = join(".", $part1, $part2);
print $basedomain;

This calls split on $domain using '.' as the delimiter, the [-2, -1]
tell it to return the next to last element ('fire' in this case) and the
last ('org').

Now for the devil's advocate part... While this does split up domain
names how you might think you want them... take into consideration
domain names like... www.theregister.co.uk?  This would only leave
'co.uk', which in my experience is never what I was really wanting to
find.  You may be in a controlled environment where this situation never
comes up but I can assure you that it's been a pain in my side more than
once.

Tim.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to