2

This is my problem: http://regexr.com?2temn

I'm sure it's pretty simple for some of you regex masters.

Cheers!

wilsonpage
  • 17,341
  • 23
  • 103
  • 147
  • 1
    Please post the problem here instead of linking it to an external page that might be gone soon. People without Flash players (iOS, anyone?), can't see the problem at all. And even if I turn off my Flash blocker and see the site, I still don't understand what exactly you're trying to do. – Tim Pietzcker Apr 01 '11 at 14:50
  • you should rephrase your question. links to an external sites are fine but the question must be comprehensive also without this additional info. Also name where you're using this regex. There are many flavors of regex... – bw_üezi Apr 01 '11 at 14:54
  • @Tim confirm not working with iOS – bw_üezi Apr 01 '11 at 15:00
  • @Tim, why do you use a flash blocker? – Kit Apr 01 '11 at 15:19
  • @Christopher: Because all the annoying ads are Flash ads. There is not much useful Flash content around IMO. Regexr being an exception, of course. – Tim Pietzcker Apr 01 '11 at 15:56

5 Answers5

3

This also works:

(?<=\.|)\w+\.\w+$

Tested only with PHP.

Kit
  • 4,095
  • 7
  • 39
  • 62
2

Grab domain after (possible) sub domain
is in fact the same as
grab domain before top level domain

it's just get the domain name from a URL.

possible duplicate

Community
  • 1
  • 1
bw_üezi
  • 4,483
  • 4
  • 23
  • 41
1

Regex (generic form) :
/^(?:https?://)?(?:([\w_.-]+?).)*[\w_-]+\.\w+.+$/i

Test :

http://subdomain.domain.tld/foo/bar.html      => One match    (subdomain)
http://subdomain.subdomain2.domain.tld/bar    => Two submatches (subdomain, subdomain2)
http://justdomain.tld                         => NO match

Tested with C#.
C# version of the regex :

 ^(?:http://)?(?:([\w+_.-]+?)\.)*[\w+_-]+\.\w+.+$

DEMO

Stephan
  • 41,764
  • 65
  • 238
  • 329
1

Try with:

(\w+\.\w+)[\r\n]+

It matches string with dot inside before new line character

hsz
  • 148,279
  • 62
  • 259
  • 315
0

I adjusted your version slightly:

(?:\.|)\w+(\.\w+){1,}

I just made the trailing ".xyz" part be a separate token to loop one or many times ("{1,}").