Python 正则表达式匹配字符串中的http链接方法
时间:2021-01-28 10:21:57|栏目:Python代码|点击: 次
利用Python正则表达式匹配字符串中的http链接。主要难点是用正则表示出http 链接的模式。
import re pattern = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+') # 匹配模式 string = 'Its after 12 noon, do you know where your rooftops are? http://tinyurl.com/NYCRooftops ' url = re.findall(pattern,string) print url >>['http://tinyurl.com/NYCRooftops']
栏 目:Python代码
下一篇:python中range()与xrange()用法分析
本文标题:Python 正则表达式匹配字符串中的http链接方法
本文地址:http://www.codeinn.net/misctech/52448.html






