【发布时间】:2023-03-24 07:03:01
【问题描述】:
我有一个cols 列表如下:
['Wed Estimate 6/10', 'Thu Estimate 6/11', 'Fri Estimate 6/12', 'Next Estimate 6/15-6/19']
当我尝试以下操作时:
re.findall(r'\s\d/\d\w-\d/\d\w', cols[3])
我得到 [' 6/15-6/19'] 但当我尝试时
[re.findall(r'\s\d/\d\w|\s\d/\d\w-\d/\d\w', x) for x in cols]
我收到[[' 6/10'], [' 6/11'], [' 6/12'], [' 6/15']]
我想实现以下目标:
[[' 6/10'], [' 6/11'], [' 6/12'], [' 6/15-6/19']]
我不确定为什么正则表达式的行为如上。
【问题讨论】:
标签: python regex list python-3.8