【发布时间】:2020-10-19 00:27:26
【问题描述】:
我要吐槽以下日期列表:
Month=['1 October 2020 to 31 October 2020',
'1 October 2020 to 31 October 2020',
'1 October 2020 to 31 October 2020',
'1 October 2020 to 31 October 2020',
'1 October 2020 to 31 October 2020']
想要的输出如下:
Month = [['1 October 2020', '31 October 2020'],
['1 October 2020', '31 October 2020'],
['1 October 2020','31 October 2020'],
['1 October 2020', '31 October 2020'],
['1 October 2020','31 October 2020']]
如何使用正则表达式来做到这一点。
我使用了Month.str.split('to'),但这不能正常工作,因为十月包含to,结果将十月分成三个字符串。因此,我想我必须为此使用regex。实现这一目标的最佳方法是什么?
【问题讨论】:
标签: python regex string list split