in reply to Re: More efficient way to truncate long strings of the same character
in thread More efficient way to truncate long strings of the same character
s/((.)\1{2})\1+/$2/g
I think you might have mixed up your '1's and '2's.
use strict; use warnings; my $str = q{aabbbbcddddddee}; print qq{Starting string\n $str\n}; # Your regex. $str =~ s/((.)\1{2})\1+/$2/g; print qq{Original regex\n $str\n}; # I think this is correct. $str = q{aabbbbcddddddee}; $str =~ s/((.)\2{2})\2+/$1/g; print qq{Corrected regex\n $str\n};
Produces
Starting string aabbbbcddddddee Original regex aabbbbcddddddee Corrected regex aabbbcdddee
This might affect the benchmark a little.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: More efficient way to truncate long strings of the same character
by mr_mischief (Monsignor) on Oct 30, 2008 at 23:37 UTC |