From: Ajithkumar Warrier Date: 2006-10-18T06:29:03+09:00 Subject: Re: Splitting a sentence with delimiter preserved On 10/17/06, Gavin Kistner wrote: That was very quick. Thank you. > From: Ajithkumar Warrier [mailto:a.varier@gmail.com] > > I am a newbie and the answer to this might be too simple. > > How do I improve the example below and reduce the number of passes > > over the string? > > > > string = "This is an example string. The purpose is to save the > > delimiter during split. Does this work. Great!!!." > > > > re = /(\.\s+)(\D)/ > > string.gsub!(re,'\1'+'#'+'\2') > > b = string.split('#') > > puts b > > p string.scan( /\w[^.!?]+\S+/ ) > > #=> ["This is an example string.", "The purpose is to save the delimiter > during split.", "Does this work.", "Great!!!."] > >