我想将第一次出现的日期或一般的正则表达式带到我的文本开头:
示例:
"I went out on 1 sep 2012 and it was better than 15 jan 2012"
我想得到
"1 sep 2012, I went out on and it was better than 15 jan 2012"
我正在考虑替换"1 sep 2012"
为",1 sep 2012,"
,然后从中删除字符串,","
但我不知道该写什么,而不是replace_with
:
line = re.sub(r'\d+\s(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s\d{4}', 'replace_with', line, 1)
有什么帮助吗?