php - 怎么正则匹配网址中间的域名
本文介绍了php - 怎么正则匹配网址中间的域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
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/
求助!!!
解决方案
php不会,这是python的,这只是个参考。其他情况自己多思考.
import re
pattern=re.compile(r'\.([^\.]*?)\.[^\.]*?$')
a=re.findall(pattern,'www.ab.baidu.com')
print a
#输出['baidu']
这篇关于php - 怎么正则匹配网址中间的域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文