vi substitution

Hello, I'm trying to do a substitution in vi. which adds a field for the year to a line.
If the line doesnt include a year, it should still add a field (although empty)

the fields are:
Country:number:number:name(and sometimes year):place
this is a desired in and output:

[LEFT]

 
Sweden:55:32:John 1898 cyclone:Kortsnau
Belize:73:27:Dolal 01:Bodville
should become
Sweden:55:32:John 1898 cyclone:1898:Kortsnau
Belize:73:27:Dolal 01::Bodville

I dont know how you can place a wildcard on a group: I tried this:

:1,$s/^\(.* \)\([0-9][0-9][0-9][0-9]\)*\(.*\):\(.*\)$/\1\2\3:\2:\4/g

can anybody tell me how it is done porperly?[/LEFT]

Hi,

My solution:

$ # Check Vim Version.
$ vim -h | head -1 | sed 's/\([^(]*\).*/\1/'
VIM - Vi IMproved 7.3 

(Inside Vim):

:%s/\m\%(.\{-}:\)\{3}\(.\{-}\(\d\{4}\).\{-}\|.\{-}\):/&\2:/

Regards,
Birei

If you don't have vim you can do with standard vi but it requires two replaces. First puts extra blank field in the 2nd last position, and 2nd populates year for those that have it:

%s/.*:/&:/
%s/\(.*\)\([0-9][0-9][0-9][0-9]\)\(.*\)::/\1\2\3:\2:/

You could get a little more specific and ensure date is only in 4th field, but your original replace didn't seem to worry about this. Perhaps 4 digit numbers never appear in fields 1-3?