Re: String#split: unxepected result
by Jan Svitok other posts by this author
Oct 31 2006 2:09AM messages near this date
String#split: unxepected result
|
Re: String#split: unxepected result
On 10/31/06, Kirill Shutemov <k.shutemov@[...].com> 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?
If there are any groups in the delimiter, they are output as well.
This is not documented in RDoc, only in the PickAxe book.
It's useful when you want to keep the delimiters.
Thread:
Kirill Shutemov
Jan Svitok
Vincent Fourmond
Robert Klemme
|