【问题标题】:Why does this regex return None [duplicate]为什么这个正则表达式返回 None [重复]
【发布时间】:2019-04-20 14:40:26
【问题描述】:

我无法弄清楚为什么这不匹配。如果有人可以在这里帮助我,我将不胜感激。

print(re.match(r"Newton", "Isaac Newton , physicist"))

【问题讨论】:

  • re.match 只匹配字符串的start
  • 因为你的字符串不是以Newton开头的。也许你想要re.search
  • python 2.7 的 re 模块的文档在这里 docs.python.org/2/library/re.html - 向下滚动以找到 match

标签: python regex string match


【解决方案1】:

re.match 仅匹配字符串的开头,使用re.search 查找字符串中任意位置的第一个匹配项(参见documentation)。

【讨论】:

  • 至少链接到 Python 文档...?
  • 刚刚添加了它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-21
  • 1970-01-01
  • 1970-01-01
  • 2019-12-08
  • 1970-01-01
相关资源
最近更新 更多