On Aug 12, 3:06 am, Simon Kr?ger <SimonKroe... / gmx.de> wrote:
> Pe?a schrieb:
>
> > From: William James [mailto:w_a_x_... / yahoo.com]
> > # s = "ZBBBCZZ"
> > #     ==>"ZBBBCZZ"
> > # s.scan( /((.)\2*)/ ).transpose.first
> > #     ==>["Z", "BBB", "C", "ZZ"]
> > # s.gsub( /(.)(?!\1)/, "\\1\n" ).split
> > #     ==>["Z", "BBB", "C", "ZZ"]
>
> > ruby hacker, James, that is cool! gotta keep this.
> > kind regards -botp
>
> Yeah, nice!
>
> i think one can simplify from
>
> s.gsub( /(.)(?!\1)/, "\\1\n" ).split
>
> to
>
> s.gsub(/(.)\1*/, '\0 ').split
>
> ?
>
> cheers
>
> Simon

Yes, with the possible exception of
"\\1\n" .  I was anticipating the need to allow
the string to contain any character but a
newline.

s = 'ZBBBC   ZZ'
    ==>"ZBBBC   ZZ"
s.gsub(/(.)\1*/, "\\0\n").split("\n")
    ==>["Z", "BBB", "C", "   ", "ZZ"]