【发布时间】:2022-06-18 03:20:41
【问题描述】:
FindAll 函数没有给出匹配的字符串。相反,它给出了一个我无法理解的输出。
import re
text = "carpet and car"
pattern = r"car(pet)?"
match = re.findall(pattern,text)
if match:
print(match)
else:
print("No match")
输出:
['pet', '']
预期输出:
['car', 'carpet']
【问题讨论】:
-
r"(car(pet)?)"呢?
标签: python python-3.x regex findall