Regular expression to parse out "host" part of URL strin

Instead of beating yourself up trying to come up with a regex, just
stick the 'http://' in front of it yourself.

unless path.index('http://', 0)
   path = 'http://' + path
   host = URI.parse(path).host
end

It's not necessarily the most robust solution, but you get the general
idea.

Regards,

Dan

···

-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Wes Gamble
Sent: Monday, April 17, 2006 10:05 AM
To: ruby-talk ML
Subject: Re: Regular expression to parse out "host" part of URL strin

Daniel,

I have that :).

I'm trying to handle the case when I get a "URL" without the http://

Wes

Berger, Daniel wrote:

···

-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Wes Gamble
Sent: Monday, April 17, 2006 10:05 AM
To: ruby-talk ML
Subject: Re: Regular expression to parse out "host" part of URL strin

Daniel,

I have that :).

I'm trying to handle the case when I get a "URL" without the http://

Wes

Instead of beating yourself up trying to come up with a regex, just
stick the 'http://' in front of it yourself.

Definitely a solution, but the regexp shouldn't be that complicated too.

url.scan(%r{(?:.+://)?([^/]+)}).first.first

should do the trick. (?) well i hope thats not like the email-regexp...

cheers

Simon

"Berger, Daniel" <Daniel.Berger@qwest.com> writes:

unless path.index('http://', 0)

  unless path.index('http://') == 0

···

   path = 'http://' + path
   host = URI.parse(path).host
end

It's not necessarily the most robust solution, but you get the general
idea.
Regards,

Dan

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org