From: Vincent Fourmond Date: 2006-10-31T19:08:47+09:00 Subject: Re: String#split: unxepected result Kirill Shutemov wrote: > irb(main):001:0> "aabbcc".split(/bb/) > => ["aa", "cc"] > irb(main):002:0> "aabbcc".split(/(bb)/) > => ["aa", "bb", "cc"] > irb(main):003:0> "aabbcc".split(/bb(c)?/) > => ["aa", "c", "c"] > > The last two result is unexpected for me. Can anybody explain it? You have a capturing group in the last RE. In this case, split also returns capturing groups. See for instance >> str = "abcd" => "abcd" >> p str.split(/(b)/) ["a", "b", "cd"] The string is split into "a" and "cd", and in the middle you get the result of the capturing group, "b". You want a non-capturing group, (?:c) instead of (c) Cheers ! Vince -- Vincent Fourmond, PhD student http://vincent.fourmond.neuf.fr/