python中的lookback

2024-04-20 10:45:31 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我有:

string = "2 dogs. 4 cats. 9 horses. 7 goats"

我想匹配数字前面的每个单词。你知道吗

我试过:

matches = re.search(r"(?<=\d+) \w+", string)

但它不起作用。你知道吗


Tags: researchstring数字单词matchesdogscats