php - 怎么正则匹配网址中间的域名
淡淡烟草味
淡淡烟草味 2017-05-16 13:10:17
0
2
524
https://so.m.sm.cn/
https://m.sm.cn/
https://www.google.com/
https://m.sogou.com/
https://wap.sogou.com/
https://m.baidu.com/
https://www.google.fr/
https://wisd.sogou.com/

正则要怎么写,只想要提取这些域名中间的如:baidu、sm、google、sogou

单独的这样的https://m.sm.cn/会写,
加上这个就不会写了https://so.m.sm.cn/
求助!!!

淡淡烟草味
淡淡烟草味

reply all(2)
巴扎黑

php doesn’t work, this is for python, this is just a reference. In other cases, think more on your own.

import re

pattern=re.compile(r'\.([^\.]*?)\.[^\.]*?$')
a=re.findall(pattern,'www.ab.baidu.com')
print a 
#输出['baidu']
仅有的幸福
preg_match('#://([\w\-\.]+)/?\b#',$string,$m) && $domain=$m[1];
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!