网络编程
位置:首页>> 网络编程>> Python编程>> Python 正则表达式匹配字符串中的http链接方法

Python 正则表达式匹配字符串中的http链接方法

作者:张土豆  发布时间:2022-02-11 03:02:13 

标签:Python,正则,表达式,http

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

来源:https://blog.csdn.net/potato012345/article/details/78215754

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com