--Apple-Mail=_4C95F942-CC72-4696-AD97-A70291297D01
Content-Type: multipart/alternative;
	boundary="Apple-Mail=_1317DC28-2A5D-41C7-800D-0F7979AF1418"


--Apple-Mail=_1317DC28-2A5D-41C7-800D-0F7979AF1418
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

Hello,

On 5 =CE=99=CE=BF=CF=85=CE=BD 2014, at 17:03 , Adam Wenham =
<adamwenham64 / gmail.com> wrote:

> Hi guys,
>=20
> I'm having some problems on good old Codewars, writing a method that =
can take a URL and return just the domain.=20
>=20
> 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.
>=20
> Here are my tests:
> Test.assert_equals(domain_name("http://github.com/carbonfive/raygun"), =
"github")=20
> Test.assert_equals(domain_name("http://www.zombie-bites.com"), =
"zombie-bites")=20
> Test.assert_equals(domain_name("https://www.cnet.com"), "cnet")=20
>=20
> Here's my method:
> def domain_name(url)
>   url.match(/https*:\/\/w*\.*(\w*\-*\w*)./)
> end
>=20
> As far as I can tell, this should work. Any ideas on what I'm doing =
wrong? Thanks!

I tested your code and returns 'https://' too, so your regexp is wrong:
--
$ cat test.rb&& ruby test.rb=20

def domain_name(url)
    puts url.match(/https*:\/\/w*\.*(\w*\-*\w*)./).to_s
end

list =3D %w{https://github.com/carbonfive/raygun =
http://www.zombie-bites.com  https://www.cnet.com}


list.each {|x| domain_name(x)}

=3D> https://github.
=3D> http://www.zombie-bites.
=3D> https://www.cnet.
--

You could adjust the regexp to match a given set of domains domain =
names[1]. But the problem is unsolvable using regular expressions[2]. In =
theory you should create a list with all the available domain names, =
(maybe a google search will even give you a TXT file) and then write a =
complicate set of instructions to match those. Only this way you might =
get a complete solution IMHO.

Best regards,


[1] =
http://stackoverflow.com/questions/12772423/regex-match-main-domain-name

[2] http://stackoverflow.com/a/12772473/577133


Panagiotis (atmosx) Atmatzidis

email:	atma / convalesco.org
URL:	http://www.convalesco.org
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5

"As you set out for Ithaca, hope the voyage is a long one, full of =
adventure, full of discovery [...]" - C. P. Cavafy





--Apple-Mail=_1317DC28-2A5D-41C7-800D-0F7979AF1418
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Dutf-8"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space;">Hello,<div><br><div><div>On 5 =CE=99=CE=BF=CF=85=CE=BD=
 2014, at 17:03 , Adam Wenham &lt;<a =
href=3D"mailto:adamwenham64 / gmail.com">adamwenham64 / gmail.com</a>&gt; =
wrote:</div><br class=3D"Apple-interchange-newline"><blockquote =
type=3D"cite"><div dir=3D"ltr">Hi guys,<div><br></div><div>I'm having =
some problems on good old Codewars, writing a method that can take a URL =
and return just the domain.&nbsp;</div><div><br></div><div>I've managed =
to create a Regex in Rubular (<a =
href=3D"http://rubular.com/r/C7wAZRq8OA">http://rubular.com/r/C7wAZRq8OA</=
a>) that passes my tests, but I'm having trouble implementing it =
properly.</div>
<div><br></div><div>Here are my tests:</div><div><div><font =
face=3D"courier new, monospace">Test.assert_equals(domain_name("<a =
href=3D"http://github.com/carbonfive/raygun">http://github.com/carbonfive/=
raygun</a>"), "github")&nbsp;</font></div>
<div><font face=3D"courier new, =
monospace">Test.assert_equals(domain_name("<a =
href=3D"http://www.zombie-bites.com/">http://www.zombie-bites.com</a>"), =
"zombie-bites")&nbsp;</font></div><div><font face=3D"courier new, =
monospace">Test.assert_equals(domain_name("<a =
href=3D"https://www.cnet.com/">https://www.cnet.com</a>"), =
"cnet")</font>&nbsp;</div>
<div><br></div><div>Here's my method:</div><div><div><font face=3D"courier=
 new, monospace">def domain_name(url)</font></div><div><font =
face=3D"courier new, monospace">&nbsp; =
url.match(/https*:\/\/w*\.*(\w*\-*\w*)./)</font></div>
<div><font face=3D"courier new, =
monospace">end</font></div></div><div><font face=3D"courier new, =
monospace"><br></font></div><div><font face=3D"arial, helvetica, =
sans-serif">As far as I can tell, this should work. Any ideas on what =
I'm doing wrong? =
Thanks!</font></div></div></div></blockquote><div><br></div><div>I =
tested your code and returns '<a href=3D"https://'">https://'</a> too, =
so your regexp is wrong:</div><div>--</div><div>$ cat test.rb&amp;&amp; =
ruby test.rb&nbsp;<br><br>def domain_name(url)<br>&nbsp; =
&nbsp;&nbsp;puts =
url.match(/https*:\/\/w*\.*(\w*\-*\w*)./).to_s<br>end<br><br>list =3D =
%w{<a =
href=3D"https://github.com/carbonfive/raygun">https://github.com/carbonfiv=
e/raygun</a> <a =
href=3D"http://www.zombie-bites.com">http://www.zombie-bites.com</a>&nbsp;=
&nbsp;<a =
href=3D"https://www.cnet.com">https://www.cnet.com</a>}<br><br><br>list.ea=
ch {|x| domain_name(x)}</div><div><br>=3D&gt; <a =
href=3D"https://github">https://github</a>.<br>=3D&gt; <a =
href=3D"http://www.zombie-bites">http://www.zombie-bites</a>.<br>=3D&gt; =
<a =
href=3D"https://www.cnet">https://www.cnet</a>.<br>--</div></div><div><br>=
</div><div>You could adjust the regexp to match a given set of domains =
domain names[1]. But the problem is unsolvable using regular =
expressions[2]. In theory you should create a list with all the =
available domain names, (maybe a google search will even give you a TXT =
file) and then write a complicate set of instructions to match those. =
Only this way you might get a complete solution =
IMHO.</div><div><br></div><div>Best regards,</div><br><div =
apple-content-edited=3D"true">
<div style=3D"color: rgb(0, 0, 0); letter-spacing: normal; orphans: =
auto; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: auto; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div =
style=3D"color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space;"><div style=3D"color: rgb(0, 0, 0); letter-spacing: =
normal; orphans: auto; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: auto; word-spacing: =
0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div =
style=3D"color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space;"><div style=3D"color: rgb(0, 0, 0); font-family: =
Helvetica; font-style: normal; font-variant: normal; font-weight: =
normal; letter-spacing: normal; line-height: normal; orphans: 2; =
text-align: -webkit-auto; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div =
style=3D"color: rgb(0, 0, 0); font-family: Helvetica; font-style: =
normal; font-variant: normal; font-weight: normal; letter-spacing: =
normal; line-height: normal; orphans: 2; text-align: -webkit-auto; =
text-indent: 0px; text-transform: none; white-space: normal; widows: 2; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: =
break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space;"></div><br>[1]&nbsp;<a =
href=3D"http://stackoverflow.com/questions/12772423/regex-match-main-domai=
n-name">http://stackoverflow.com/questions/12772423/regex-match-main-domai=
n-name</a></div><div style=3D"color: rgb(0, 0, 0); font-family: =
Helvetica; font-style: normal; font-variant: normal; font-weight: =
normal; letter-spacing: normal; line-height: normal; orphans: 2; =
text-align: -webkit-auto; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space;"><br></div><div style=3D"color: rgb(0, 0, 0); =
font-family: Helvetica; font-style: normal; font-variant: normal; =
font-weight: normal; letter-spacing: normal; line-height: normal; =
orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: =
none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space;">[2]&nbsp;<a =
href=3D"http://stackoverflow.com/a/12772473/577133">http://stackoverflow.c=
om/a/12772473/577133</a></div><div style=3D"color: rgb(0, 0, 0); =
font-family: Helvetica; font-style: normal; font-variant: normal; =
font-weight: normal; letter-spacing: normal; line-height: normal; =
orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: =
none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space;"><br></div><div style=3D"color: rgb(0, 0, 0); =
font-family: Helvetica; font-style: normal; font-variant: normal; =
font-weight: normal; letter-spacing: normal; line-height: normal; =
orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: =
none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space;"><br>Panagiotis (atmosx) =
Atmatzidis<br><br>email:<span class=3D"Apple-tab-span" =
style=3D"white-space: pre;">	</span><a =
href=3D"mailto:atma / convalesco.org">atma / convalesco.org</a><br>URL:<span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	=
</span>http://www.convalesco.org<br>GnuPG ID: 0x1A7BFEC5<br>gpg =
--keyserver pgp.mit.edu --recv-keys&nbsp;1A7BFEC5<br><br>"<span =
style=3D"orphans: auto; widows: auto;">As you set out for =
Ithaca,&nbsp;</span><span style=3D"orphans: auto; widows: auto;">hope =
the voyage is a long one,&nbsp;</span><span style=3D"text-align: =
-webkit-auto; orphans: auto; widows: auto;">full of adventure, full of =
discovery [...]</span><span style=3D"text-align: -webkit-auto;">" =
-&nbsp;C. P. Cavafy</span></div><div style=3D"color: rgb(0, 0, 0); =
font-family: Helvetica; font-style: normal; font-variant: normal; =
font-weight: normal; letter-spacing: normal; line-height: normal; =
orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: =
none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space;"><br></div><div style=3D"color: rgb(0, 0, 0); =
font-family: Helvetica; font-style: normal; font-variant: normal; =
font-weight: normal; letter-spacing: normal; line-height: normal; =
orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: =
none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space;"><br></div></div></div></div></div><br =
class=3D"Apple-interchange-newline">
</div>
<br></div></body></html>=

--Apple-Mail=_1317DC28-2A5D-41C7-800D-0F7979AF1418--

--Apple-Mail=_4C95F942-CC72-4696-AD97-A70291297D01
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename=signature.asc
Content-Type: application/pgp-signature;
	name=signature.asc
Content-Description: Message signed with OpenPGP using GPGMail

-----BEGIN PGP SIGNATURE-----
Comment: Public Key Encryption

iQIcBAEBAgAGBQJTkJBbAAoJEPy01a8ae/7FWFcP/0MZ11/ztcqdJWjwRj1Dpr5T
h81IVRhv2RKZ4DYa6QlEBv92T8A7UJGBNhx8D2MUNouUgo6Jt7HFtYH1l0U230Ky
IDzJldbNYBiRnbohKoTSuy/M4akobDRT4TtpjWzK/P6/3aGvfiHW67t+yY1bePUE
g4D+I0lEuq9i7ko2XNWbV42lZjzvOTRQcZUQt36GBGU+Ttc0MC3Z9OROPTQ3Ntpz
3y+mPEEMCfB5KlTxHI1TRQ72Fapn5YgRdWBlaoZYpL66epih/dCalooUiTR3sxrH
FF5IFnGO/jxfJEG5rCvYuUjWu0KD9JCNm9pak/RpN1ySdvjfdqUdrII7cubGMbzh
oXImseH/bfmzom5vu8PtlXknp8FGbz4CstX3AbFIIXJ5Qs0srNEjTZNFQakV5L9O
zUZe6I1h5IAc9jcR7WsAA4q7zM9ZvpMJEAr9zSzRWNyarSEF0gFaldsHXogJDDav
29R6Bwztj1giC5Xj4P/8jVw+4J1QwEO5u9kzKm2ktBf+68Ajt0ULj9OMQYQcqusk
UFRgmw+smlPog8dOM6b07OXmcuedpVGPiXaAMQF4R4llp1JMPv6miOzHnf9+8IUo
/gofHCVA026yzIRm18glFbKzKFtQZZCwMf9c7I1cUzWryeckXS1rymOX21ewEKy9
dPj/jnv/vR11h8YRSUbI
=BnhK
-----END PGP SIGNATURE-----

--Apple-Mail=_4C95F942-CC72-4696-AD97-A70291297D01--