是否可以在前视和后视搜索中包含标记?
示例:
str = "my cat is the best pet in the world"
re.findall('(?s)(?<=cat)(.*?)(?=pet)', str)我想要的是“猫是最好的宠物”
谢谢!
发布于 2020-03-09 18:55:53
你应该直接搜索\bcat.*?pet\b,然后用lookaround放弃:
str = "my cat is the best pet in the world"
m = re.findall(r'\bcat.*?pet\b', str)
print(m)这将打印:
['cat is the best pet']https://stackoverflow.com/questions/60599006
复制相似问题