首页 > 解决方案 > 为什么我的正则表达式不起作用,它有一个“或”

问题描述

当我这样做时,我得到了预期,re.findall(r'applepast[ry|e]', s17)但我无法理解为什么我需要在+这里给予,因为我已经明确地给予e|ry

import re
s17 = 'find word that match applepastry, applepie or applepaste'
re.findall(r'applepast[ry|e]', s17)

我的出局

['applepastr', 'applepaste']

我的预期

['applepastry', 'applepaste']

标签: pythonregex

解决方案


推荐阅读