首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从字符串中提取所有urls的正则表达式

从字符串中提取所有urls的正则表达式
EN

Stack Overflow用户
提问于 2016-08-03 05:29:31
回答 4查看 2.8K关注 0票数 0

我有一个这样的字符串

http://example.com/path/topage.htmlhttp://twitter.com/p/xyanhshttp://httpget.org/get.zipwww.google.com/privacy.htmlhttps://goodurl.net/

我想提取所有的网址/网页地址到一个数组。例如

urls = ['http://example.com/path/topage.html','http://twitter.com/p/xyan',.....]

这是我的方法,但没有奏效。

代码语言:javascript
复制
import re
strings = "http://example.com/path/topage.htmlhttp://twitter.com/p/xyanhshttp://httpget.org/get.zipwww.google.com/privacy.htmlhttps://goodurl.net/"
links = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', strings)

print links
// result always same as strings 
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38730782

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档