码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-03-08 20:50:09      阅读:906      评论:0      收藏:0      [点我收藏+]

标签:表达式   port   正则表达   http   imp   findall   find   regular   域名   

使用正则表达式匹配以 .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 使用正则表达式匹配URL网址

标签:表达式   port   正则表达   http   imp   findall   find   regular   域名   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!