From: Ben Nagy Date: 2006-06-27T18:14:26+09:00 Subject: Re: string manipulation > -----Original Message----- > From: Paul Battley [mailto:pbattley@gmail.com] [...] > On 27/06/06, Ben Nagy wrote: > > then I got: > > > > str.sub(/\d{2}/,'\0-').gsub(/\d{4}(?!$)/,'\0-') > > str.gsub(/(?:^\d{2}|\d{4}(?=.))/, '\0-') > > Paul Although it's derivative, if you sacrifice a little precision (bad inputs will kill the regexp solutions anyway) then: str.gsub(/^..|.{4}(?!$)/,'\0-') seems to work for me... ;) ben