【问题标题】:FindAll is not giving the matching stringFindAll 没有给出匹配的字符串
【发布时间】: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


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-18
  • 2023-01-25
  • 2023-03-08
  • 1970-01-01
  • 2016-05-16
  • 1970-01-01
相关资源
最近更新 更多