On 31.10.2006 10:49, 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?

#split returns matching groups of the split pattern if there are 
capturing groups:

irb(main):008:0> "aabbcc".split(/bb(c)?/)
=> ["aa", "c", "c"]
irb(main):009:0> "aabbcc".split(/bb(?:c)?/)
=> ["aa", "c"]
irb(main):010:0> "aabbcc".split(/(bb(?:c)?)/)
=> ["aa", "bbc", "c"]

Regards

	robert