in reply to Using regex to match double letters, and only double letters
a little trick. (Still uses regexes, but nothing complicated, not even any captures.)
sub find_runs { local $_ = shift; $_ ^= substr $_, 1; # string shifted left one char. my @r; push @r, [ $-[0], $+[0] - $-[0] + 1 ] while /\x00+/g; @r } # find the 'oo' and the 'ttt' my $s = "look for doubled lettters"; for my $r ( find_runs($s) ) { print substr $s, $r->[0], $r->[1]; }
|
|---|