Reputation: 1749
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?
Upvotes: 1
Views: 44
Reputation: 368954
Capturing group number starts from 1
, not from 0
.
So the command should be:
:%s/-\(\d\),/-0\1,/g
Upvotes: 2