Python 使用正则表达式匹配URL网址

使用正则表达式匹配以 .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']

 

 

 

 

 

    

posted @ 2019-03-08 20:42  孔雀东南飞  阅读(10339)  评论(0编辑  收藏  举报