1

I'm using this code to preg match for *.domain.com but need it changed to also include foreign domains which have a few periods like *.domain.co.uk. Any helps appreciated thanks

if (trim(preg_match('!^https?://([^/]+\.)?domain\.com(/|#|$)!i', $documentLink->getAttribute('href'))))

Just an update that i'm looking to match *.domain.(any TLD) not just co.uk

Thanks

Anagio
  • 3,005
  • 9
  • 44
  • 81
  • Maybe check out this question: http://stackoverflow.com/questions/399932/can-i-improve-this-regex-check-for-valid-domain-names – Tim Lytle Oct 16 '11 at 05:45
  • What you are going to do with http://www.nic.tr and http://www.odtu.edu.tr and http://www.cosmos.1.bg and http://www.cosmos.bg/ ? – ilhan Oct 16 '11 at 06:24
  • Note that http://cosmos1.bg is ccTLD. There does not exist something like http://1.bg. – ilhan Oct 16 '11 at 06:29
  • I tested this "(preg_match('/(?P[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) " and it gets nic.tr odtu.edu.tr, the only domain it doesn't pickup is cosmos.1.bg, i'm not good with regex but I think it's because of the single character in the middle. What change can I make? Thanks – Anagio Oct 16 '11 at 08:01

3 Answers3

1
!^https?://([^/]+\.)?domain(.com|co.uk)(/|#|$)!i
user956584
  • 5,316
  • 3
  • 40
  • 50
0
!^(https?://)?([\w-]+\.)?domain(\.[a-z]{2,5})+(/|#|$)!i
ghbarratt
  • 11,496
  • 4
  • 41
  • 41
0
!^https?://([^/]+\.)?domain[.a-z]+(/|#|$)!i
Ruel
  • 15,438
  • 7
  • 38
  • 49