On 14-06-02, 10:51, Roelof Wobben wrote:
> I try to find a regex which find only the domain name without the .com
> or .nl
>
> I tried :
>
> \w{3+}

You need to limit your expression more, your example will find ANY 3 
"word" characters, even numbers and punctuation, and even if there are 
MORE word characters around them.

You could do this with a capture group (here, named "tld"):

     regex = %r{
       \.            # one dot,
       (?<tld>       # capture as "tld":
         [a-z]{3}+   # 3+ alpha characters (note: not \w)
       )
       $             # at the end of a line/string
     }x
     "http://example.com".match(regex)[:tld]

Or with a positive look-behind:

     %r{
       (?<=\.)    # lookbehind for one dot,
       [a-z]{3}+  # match 3+ alpha characters
       $          # at the end of a line/string
     }
     "http://example.com".match(regex)

Another approach is using the URI library:

     URI.parse("http://example.com/").host.split(".").last

Andrew Vit