正则表达式

当前位置:正则表达式 > python

python正则表达式匹配网址

使用正则表达式匹配以 .com 或 .cn 为域名后缀的URL地址

In [1]: import re
In [2]: str = "http://www.baidu.com/"
In [3]: regular = re.compile(r'[a-zA-Z]+://[^s]*[.com|.cn]')
In [4]: re.findall(regular, str)                             
Out[4]: ['http://www.baidu.com']

python正则表达式匹配网址通用代码
import re
pattern = re.compile(ur'[a-zA-z]+://[^s]*')
str = u''
print(pattern.search(str))


相关文章
苏ICP备2022026517号-2  |   苏公网安备 32081202000316号
淮安先皓网络科技有限公司 © 版权所有  联系我们