我從一個網站復制了一個書籍串列及其 URL,當粘貼到 word doc 中時該串列變成一個字串,我想在新行中分隔每個標題和 URL:
復制清單:
初等代數
https://regexr.com/
此外,在 python 中,它只回傳第一個匹配項,我不知道如何用 () 將它分組,然后用 *
uj5u.com熱心網友回復:
嘗試(regex101):
import re s = """Elementary Algebra https://amzn.to/3S7yG0Y Pre-Algebra https://amzn.to/3TpW8HK Discrete Mathematical Structures https://amzn.to/3eBYogb Discrete Mathematics and its Applications https://amzn.to/3TvfThe Discrete and Combinatorial Mathematics https://amzn.to/3CELUfO""" pat = re.compile(r"\s*(.*?)\s (https?://\S )") print(pat.findall(s))
印刷:
[ ("Elementary Algebra", "https://amzn.to/3S7yG0Y"), ("Pre-Algebra", "https://amzn.to/3TpW8HK"), ("Discrete Mathematical Structures", "https://amzn.to/3eBYogb"), ("Discrete Mathematics and its Applications", "https://amzn.to/3TvfThe"), ("Discrete and Combinatorial Mathematics", "https://amzn.to/3CELUfO"), ]
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/520759.html
標籤:Python正则表达式
上一篇:我怎么能等到值更新然后我使用它