On Wed, Nov 11, 2009 at 10:25 PM, Abhishek shukla <[email protected]>wrote:
> Hello Friends, > I need to write a regular expression which will extract and return the > domain name. > > for example > if a user parse any of the below mention url it should save only "foo.com" > > http://www.foo.com/ > http://www.foo.com/something > http://foo.com/ > https://something.foo.com/ > > Thanks for any help.. > > Thanks > abhis > > > require 'uri' urls = [ "http://www.foo.com/", "http://www.foo.com/something", " http://foo.com/", "https://something.foo.com/" ] urls.each { |url| puts URI::parse( url ).host.split( "." )[-2,2].join(".") } Good luck, -Conrad > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

