小编Mor*_*Brb的帖子

使用正则表达式重新排序字符串

我想将第一次出现的日期或一般的正则表达式带到我的文本的开头:

示例: "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)
Run Code Online (Sandbox Code Playgroud)

任何帮助?

python regex location replace

5
推荐指数
1
解决办法
2319
查看次数

标签 统计

location ×1

python ×1

regex ×1

replace ×1