in reply to Elegant way to split into sequences of identical chars?

This is almost a repeat of tye's answer, but without peking at the others I came up with
use strict; use warnings; use Data::Dumper; my @repeats; while ( 'xx556xx' =~ m/((.)(\2)*)/g ) { push @repeats, $1; } print Dumper(\@repeats);

Replies are listed 'Best First'.
Re^2: Elegant way to split into sequences of identical chars?
by eric256 (Parson) on Nov 30, 2005 at 16:25 UTC

    Forgot to post my solution early, but its similar to yours so i'll add it here.

    use Data::Dumper; my $test = "xx556xxyyy"; my @matches ; push @matches, $1 while ($test =~ /((.)\2*)/g); print Dumper(@matches);

    These solutions have the added benefit of being able to switch to just a list of chars by changeins $1 to $2. Not sure thats of any use but hey. lol. I'm mildly suprised there is no regex command to match last char, or a way to specify which groups to return and with are just used internal to the regex, I guess the need doesn't arise that often.


    ___________
    Eric Hodges $_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9'; s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;