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']

    

原文地址:https://www.cnblogs.com/pzk7788/p/10498128.html