【发布时间】:2022-01-23 13:11:31
【问题描述】:
我正在寻找匹配字符串中实际存在的模式,但 python 返回“False”,我错过了什么?
text = "123409Tue15-Feb-2022Tue22-Feb-2022Thu24-Feb-20225"
is_matched = bool(re.match("((Mon|Tue|Wed|Thu|Fri)([0-9][0-9]-[A-Z][a-z][a-z]-[0-9][0-9][0-9][0-9]))",text))
is_matched 每次都返回False...而模式存在。
如果我输入以下值,is_matched 返回True:
text = 'Tue15-Feb-2022Tue22-Feb-2022Thu24-Feb-2022'
is_matched = bool(re.match("((Mon|Tue|Wed|Thu|Fri)([0-9][0-9]-[A-Z][a-z][a-z]-[0-9][0-9][0-9][0-9]))",text))
如何排除我的模式前后的文本检查?
谢谢
【问题讨论】: