我想從參考中匹配 url。但是有些 url 中有線剎車。
示例文本 = 耶魯大學氣候變化交流專案。康涅狄格州紐黑文:xxx 大學和喬治梅森大學;2015 年。1-62。來自:https : //example.xxx.edu/wp-content/uploads/2015/04/Global-Warming-CCAM-March-2015.pdf。
想匹配:https ://example.xxx.edu/wp-content/uploads/2015/04/Global-Warming-CCAM-March-2015.pdf
uj5u.com熱心網友回復:
試試(正則運算式演示。)
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("."))
印刷:
https://example.xxx.edu/wp-content/uploads/2015/04/Global-Warming-CCAM-March-2015.pdf
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/528895.html
