문제

I have a list of dates (YYYY-M or YYYY-MM) and want to prefix 0 before the first 9 months for consistency. Data format : Date in YYYY-M or YYYY-MM followed by a comma and a number. Eg:

2012-1,789
2012-11,563

2012-1,789 should be changed to 2012-01,789. The entry `2012-11,563' should remain unchanged.

Correct output should be:

2012-01,789
2012-11,563

I tried following regular expression in Vim.

:%s/-\(\d\),/-0\0,/g

However, I get the following output:

2012-0-1,789
2012-11,563

Why am I getting an additional dash - between two digits?

도움이 되었습니까?

해결책

Capturing group number starts from 1, not from 0.

So the command should be:

:%s/-\(\d\),/-0\1,/g
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top