Hi guys,
I'm having some problems on good old Codewars, writing a method that can
take a URL and return just the domain.
I've managed to create a Regex in Rubular (http://rubular.com/r/C7wAZRq8OA )
that passes my tests, but I'm having trouble implementing it properly.
Here are my tests:
Test.assert_equals(domain_name("http://github.com/carbonfive/raygun "),
"github")
Test.assert_equals(domain_name("http://www.zombie-bites.com "),
"zombie-bites")
Test.assert_equals(domain_name("https://www.cnet.com "), "cnet")
Here's my method:
def domain_name(url)
url.match(/https*:\/\/w*\.*(\w*\-*\w*)./)
end
As far as I can tell, this should work. Any ideas on what I'm doing wrong?
Thanks!
···
--
== People often come up to me and ask "What the heck are you doing in my
shed!?" ==
Stu1
(Stu)
5 June 2014 16:46
2
/^https?:\/\/(www.)?[a-zA-Z0-9_-]*\.(com|net|org)\/?((([a-zA-Z\/0-9_-])+)?)$/
···
On Thu, Jun 5, 2014 at 10:03 AM, Adam Wenham <adamwenham64@gmail.com> wrote:
Hi guys,
I'm having some problems on good old Codewars, writing a method that can
take a URL and return just the domain.
I've managed to create a Regex in Rubular (http://rubular.com/r/C7wAZRq8OA\ )
that passes my tests, but I'm having trouble implementing it properly.
Here are my tests:
Test.assert_equals(domain_name("http://github.com/carbonfive/raygun"\ ),
"github")
Test.assert_equals(domain_name("http://www.zombie-bites.com "),
"zombie-bites")
Test.assert_equals(domain_name("https://www.cnet.com "), "cnet")
Here's my method:
def domain_name(url)
url.match(/https*:\/\/w*\.*(\w*\-*\w*)./)
end
As far as I can tell, this should work. Any ideas on what I'm doing wrong?
Thanks!
--
== People often come up to me and ask "What the heck are you doing in my
shed!?" ==