简体   繁体   English

Notepad++ Regex - 替换日期中的空格

[英]Notepad++ Regex - Replace a blank space in dates

I have a large export file from a legacy computer system.我有一个来自旧计算机系统的大型导出文件。 The dates that get exported have a [space] instead of a 0 for all single digit days or months:对于所有个位数的天或月,导出的日期都有一个[space]而不是0

1/ 1/2015 (dd/MM/yyyy) 1/ 1/2015 (日/月/年)

The first space is not a problem but the second space is.第一个空间不是问题,但第二个空间是。

I have tried to search and replace /[space] but this will replace any occurrences of /[space] in the data file - not only in dates.我试图搜索和替换/[space]但这将替换数据文件中出现的任何/[space] - 不仅仅是日期。

I have also tried to use regex find and replace as follows:我还尝试使用正则表达式查找和替换如下:

Find: / [0-9]/[0-9]+查找: / [0-9]/[0-9]+

Replace: /0[0-9]/[0-9]+替换: /0[0-9]/[0-9]+

The intended out come should be:预期的结果应该是:

Original: 1/ 1/2015原文: 1/ 1/2015

New: 1/01/2015新: 1/01/2015

However I got:但是我得到了:

Actual: 1/0[0-9]/[0-9]+实际: 1/0[0-9]/[0-9]+


Is this even possible in Notepad++ or do I have to use MS Excel?这甚至可以在 Notepad++ 中实现还是我必须使用 MS Excel?

Thanks谢谢

Find : (\\b\\d{1,2}/) +(\\d{1,2})(?=/\\d{4}\\b)查找: (\\b\\d{1,2}/) +(\\d{1,2})(?=/\\d{4}\\b)

Replace : \\1\\2替换: \\1\\2

DEMO演示

Could you try replacing (?<=/) (?=[0-9]/[0-9]+) with nothing (or 0, if you want padded single digit dates)?您可以尝试用空替换(?<=/) (?=[0-9]/[0-9]+) (或 0,如果您想要填充个位数的日期)? Works in Sublime, haven't tested NP++.在 Sublime 中工作,尚未测试 NP++。

Try this, was working perfectly in my editor.试试这个,在我的编辑器中完美运行。

Find what: (\\d/)\\s(\\d/\\d{4})找出什么: (\\d/)\\s(\\d/\\d{4})
Replace with: $10$2替换为: $10$2

The explanation of regex and output can be found in below picture.正则表达式和输出的解释可以在下图中找到。在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM