Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有:
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']