我试图用关键字“汽车”搜索所有这些短语:
eg text = 'alice: speed car, my red car, new car', 我想找'speed car', 'my red car', 'new car'。
import re
text = 'alice: speed car, my red car, new car'
regex = r'([a-zA-Z]+\s)+car'
match = re.findall(regex, text)
if match:
print(match)
但上面的代码产生:
["speed ", "red ", "new "]
代替
["speed car", "my red car", "new car"]
哪个是预期的?