From: James Edward Gray II Date: 2005-12-06T05:18:50+09:00 Subject: Re: String split drops the delimiter On Dec 5, 2005, at 2:12 PM, basi wrote: > Hello: > > string.split drops the delimiter. Thus: > > data = " This is a declarative sentence. And is this a question? > Yes! " > for sentence in data.split(/[.!?] /) > puts sentence > end > > gives > > This is a declarative sentence > And is this a question > Yes > > I'd like the result to retain the delimiter, thus: > > This is a declarative sentence. > And is this a question? > Yes! > > Any easy way to do this? split() can be asked to include it, though it puts it in a separate field: >> data = " This is a declarative sentence. And is this a question? Yes! " => " This is a declarative sentence. And is this a question? Yes! " >> data.split(/([.!?])\s+/) => [" This is a declarative sentence", ".", "And is this a question", "?", "Yes", "!"] Hope that helps. James Edward Gray II