PHP preg match *.domain.com or *.domain.co.uk

孤者浪人 提交于 2021-01-28 08:45:58

问题


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


回答1:


!^https?://([^/]+\.)?domain(.com|co.uk)(/|#|$)!i



回答2:


!^https?://([^/]+\.)?domain[.a-z]+(/|#|$)!i



回答3:


!^(https?://)?([\w-]+\.)?domain(\.[a-z]{2,5})+(/|#|$)!i


来源:https://stackoverflow.com/questions/7782591/php-preg-match-domain-com-or-domain-co-uk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!