加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 正则表达式匹配字符串上的正则表达式匹配返回无

发布时间:2020-12-20 11:09:05 所属栏目:Python 来源:网络整理
导读:参见英文答案 Python regular expression re.match,why this code does not work?????????????????????????????????????1个 我正在为一个subreddit制作一个小机器人.为此,我从trakt.tv中删除了一些数据.报废后我跑了一点正则表达式 obituarySecondary = re.m
参见英文答案 > Python regular expression re.match,why this code does not work?????????????????????????????????????1个
我正在为一个subreddit制作一个小机器人.为此,我从trakt.tv中删除了一些数据.报废后我跑了一点正则表达式

obituarySecondary = re.match(r"^([w ,."]+,d{4} ?- ?w+ d+,?d{4})",obituaryRaw).group(0)

我得到了Nathaniel Fisher,Sr.1943-2000所需的结果

现在我在obituarySecondary上运行了另一个正则表达式

timeline = "nn" + re.match(r'(d{4} ?- ?d{4})',obituarySecondary).group(0)

但这总是回归.

我在https://regex101.com/上运行了相同的正则表达式以确保我正确处理并且字符串匹配,但不在我的系统上.

解决方法

re.match()只会搜索字符串中的第一项,而是使用re.search()

有关更多详细信息,请查看this StackOverflow问题

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读