2024-04-20 10:45:31 发布
网友
假设我有:
string = "2 dogs. 4 cats. 9 horses. 7 goats"
我想匹配数字前面的每个单词。你知道吗
我试过:
matches = re.search(r"(?<=\d+) \w+", string)
但它不起作用。你知道吗
>>> s = "2 dogs. 4 cats. horses. 7 goats" >>> import re >>> re.findall(r'\d+\s(\w+)', s) ['dogs', 'cats', 'goats']
相关问题 更多 >
编程相关推荐