Splitting a sentence with delimiter preserved


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)/
b = string.split(’#’)
puts b


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs