Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^2: Extracting a domain name from a url

by rhesa (Vicar)
on Oct 15, 2006 at 18:26 UTC ( #578411=note: print w/replies, xml ) Need Help??

in reply to Re: Extracting a domain name from a url
in thread Extracting a domain name from a url

Yup, your solution does work for the majority of urls.

For the record, here are some urls that wouldn't be handled properly with your regex:

Replies are listed 'Best First'.
Re^3: Extracting a domain name from a url
by abachus (Monk) on Oct 15, 2006 at 23:02 UTC
    thanks monks, as always you show light on things i cannot see :)
Re^3: Extracting a domain name from a url
by ministry (Scribe) on Oct 16, 2006 at 01:10 UTC
    This one is one I've been using in production for a while, and seems to hold up well:

    my $url=""; my($host)=$url=~/http:\/\/([^\/]+)/;


    Update: Sorry, I'm a moe - I forgot to add the point of this post in my example!

    Good judgement comes with experience. Unfortunately, the experience usually comes from bad judgement.

      You code fails with the input you gave it. Furthermore, it doesn't work with the other example in the post to which you replied either. gives instead of gives instead of

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://578411]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2023-10-03 10:17 GMT
Find Nodes?
    Voting Booth?

    No recent polls found