From: Robert Klemme Date: 2004-12-09T22:52:28+09:00 Subject: Re: [rcr] String#split behaves odd "Brian Schr�der" schrieb im Newsbeitrag news:20041209143808.412a5f7e@black.wg... > On Thu, 9 Dec 2004 22:19:55 +0900 > Glenn Parker wrote: > > > trans. (T. Onoma) wrote: > > > On Wednesday 08 December 2004 10:00 am, Florian Frank wrote: > > > | > > > | "abc\n\ndef\nghi".split(/\n+/) > > > > > > Sorry, what are you pointing out here? > > > > It is impossible to have perfect forwards-backwards symmetry with split > > and join. When the split pattern matches more than one possible string > > of characters, there is no way to join the results of the split and > > recover the original input. > > > > That is obvious, but no argument against wanting split and join to be symmetric > for fixed split patterns. (On the other hand one could even argue, that we > "need" variable join patterns to make it symmetric again. ;) Just one note: you can use regexp grouping to get the delimiters as well as the content. That way you can join with "" and get the original back: >> "abababab".split(/b/) => ["a", "a", "a", "a"] >> "abababab".split(/(b)/) => ["a", "b", "a", "b", "a", "b", "a", "b"] There might be certain border cases though. Kind regards robert