in reply to Re: remove repeating characters from strings
in thread remove repeating characters from strings
Here's a solution that favours the longest match, finds recursive repeatitions, and uses {$n} instead of *.
This will produce:$_ = "bbbccabcabcabcdba"; my $l = length; s{((\w{$l})\2+)}{($2){@{[length($1)/length($2)]}}}g while -- $l;
Changing $_ to bbbccaabcaabcaabcdba, the above code will yield:(b){3}c(cab){3}cdba
(b){3}c(c(a){2}b){3}cdba
Abigail
|
|---|