Jano Svitok
8/12/2006 7:30:00 PM
On 8/12/06, Eero Saynatkari <eero.saynatkari@kolumbus.fi> wrote:
> Sam Kong wrote:
> > Hello Rubyists,
> >
> > I'm reading Ruby Cookbook.
> > The first chapter is about String.
> > One of the examples shows the differenct between String#split(/\s+/) and
> > String#split(/(\s+)/) without much explanation.
> > I understand what sub-grouping is in regex.
> > Bug I don't understand what role that plays in String#split.
> >
> > s = "one two three"
> >
> > p s.split(/\s+/) #=> ["one", "two", "three"]
> > p s.split(/(\s+)/) #=> ["one", " ", "two", " ", "three"]
>
> # Try this one
> p s.split /((((\s+))))/
>
> >
> > Could anybody explain it, please?
> >
> > Thanks,
> > Sam
Seems like all groups in the separator regex are output to the result array.
I wonder where is it documented, except for the source itself?
(string.c, rb_str_split_m())