首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用换行符匹配url/链接的Regex

用换行符匹配url/链接的Regex
EN

Stack Overflow用户
提问于 2022-11-07 20:52:44
回答 1查看 35关注 0票数 -2

我想要匹配references.But的url一些url有线刹车在它。

示例text =耶鲁气候变化交流项目。纽黑文,CT: xxx大学和乔治·梅森大学;2015年。第1-62页。可从以下网址获得: uploads/2015/04/Global-Warming-CCAM-March-2015.pdf. https://example.xxx.edu/wp-content/

想要匹配:https://example.xxx.edu/wp-content/uploads/2015/04/Global-Warming-CCAM-March-2015.pdf

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-07 21:04:51

尝试(Regex演示。)

代码语言:javascript
复制
txt = """\
Yale Project on Climate Change Communication. New Haven, CT: xxx University and George
Mason University; 2015. p. 1–62. Available from: https://example.xxx.edu/wp-content/
uploads/2015/04/Global-Warming-CCAM-March-2015.pdf. This is another text just for example"""


import re

pat = re.compile(r"https?://[\S\n]+")

for url in pat.findall(txt):
    print(url.replace("\n", "").strip("."))

指纹:

代码语言:javascript
复制
https://example.xxx.edu/wp-content/uploads/2015/04/Global-Warming-CCAM-March-2015.pdf
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74352789

复制
相关文章

相似问题

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