Splitting a sentence with delimiter preserved

A

Ajithkumar Warrier

Hi,

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

Thanks
Ajith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top