Marv Boyes wrote:


For example, let's say I have some dates that look like this:

         7-30-05
         12-5-2006
         10-2-06

What I'd like to end up with is this...

         07/30/2005
         12/05/2006
         10/02/2006

...without, of course, having to re-type every single one by hand. ;)

The following will do the trick, albeit you do need vim 7.0 for it:

%s/\(\d\{1,2}\)-\(\d\{1,2}\)-\(\d\{2,4}\)/\=printf('%02d\/%02d\/%4d',submatch(1),submatch(2),(submatch(3) < 100)? (2000+submatch(3)) : submatch(3))/

Explanation:
 \d\{1,2}  --- match 1 to 2 digits
 \(...\)     ---- save this matching subexpression for later
 \=       ---- execute the following expression
  submatch(...)  ---- use the subsexpression matched earlier

Regards,
Chip Campbell


Reply via email to