使用正则表达式匹配以 .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\']
使用正则表达式匹配以 .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\']
相关文章: