首页 > 解决方案 > 正则表达式匹配不正常,每次都给出空白列表

问题描述

我想从 txt 匹配 From Jun-2020 To Jun-2020,但我每次都得到空字符串。


import re

txt = "Monthly Data Item Wise Report Across Facility From Jun-2020 To Jun-2020    Data as on 24th February 2021 11:20:24 AM"
x = re.findall("^ From *[abceglnoprtuvyADFJMNOS|]{3}[\s-]\d{2,4} To *[abceglnoprtuvyADFJMNOS|]{3}[\s-]\d{2,4}", txt)

print(x)

标签: python-3.xregex

解决方案


推荐阅读