假设我有:
string = "2 dogs. 4 cats. 9 horses. 7 goats"我要匹配数字前面的每一个单词。
我试过了:
matches = re.search(r"(?<=\d+) \w+", string)但它不起作用。
发布于 2013-06-17 00:59:35
>>> s = "2 dogs. 4 cats. horses. 7 goats"
>>> import re
>>> re.findall(r'\d+\s(\w+)', s)
['dogs', 'cats', 'goats']https://stackoverflow.com/questions/17135567
复制相似问题