From: dblack@... Date: 2006-04-18T00:41:44+09:00 Subject: Re: Regular expression to parse out "host" part of URL string Hi -- On Tue, 18 Apr 2006, Wes Gamble wrote: > All, > > I am trying to write a regex to parse out the "host" part of a potential > URL. > > So if presented with > > www.cnn.com > > I want to get > > www.cnn.com > > If presented with > > www.cnn.com/ > > I want to get > > www.cnn.com > > If presented with > > www.cnn.com/some/other/stuff > > I want to get > > www.cnn.com > > This regex: /(.*)?\/*/ matches everything > This regex: /(.*)?\// matches everything including the "/" > > How can I just get the part of the string before the slash? How about: /[^\/]+/ # match one or more non-slash characters David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" PDF now on sale! http://www.manning.com/black Paper version coming in early May!