Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 May 2000 13:27:15 -0400
From:      Mitch Collinsworth <mkc@Graphics.Cornell.EDU>
To:        "Dan Larsson" <dl@tyfon.net>
Cc:        questions@FreeBSD.ORG
Subject:   Re: regexp driving me nuts, help needed! 
Message-ID:  <200005111727.NAA86965@larryboy.graphics.cornell.edu>
In-Reply-To: Message from "Dan Larsson" <dl@tyfon.net>  of "Thu, 11 May 2000 18:42:59 %2B0200." <NEBBJANJCNNAKCPFKHHFEEENCCAA.dl@tyfon.net> 

next in thread | previous in thread | raw e-mail | index | archive | help

>I need to get the domain and tld from an url.
>
>this my idea of what would match and return 'domain.com':
>echo http://www.domain.com/html.asp | sed -e 's/\([\.a-zA-Z0-9]+[a-zA-Z]{2,3}\
>)/\1 /g'
>
>But that's not what sh thinks ( it returns the whole url )
>What regexp should I use to get the desired result?

Here's a perl 1-liner:

echo http://www.domain.com/html.asp |\
 perl -e '$u=<>; $u=~s/http:\/\///; $u=~s/^www.//i; $u=~s/\/.*$//; print $u'
domain.com

This works in stages, so it doesn't depending on the starting string
always containing all syntactical elements.

-Mitch


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200005111727.NAA86965>