in reply to Replacing with multiple occurrences.
Update: as stated before, I misread the question. There is no problem with Skeeve's solution, as it does what is stated.
Because I couldn't get Skeeve's to work on my strings, I did my own version, which should work:
my $string = 'aaabcdabcddddddefgg'; $string =~ s/((.)(?(?=\2{2,})\2+))\1/$1/g; print "$string\n";
I used the 'if 2 or more of the previous string' swallow them (prior to the backtrack, but anyhow), as it wouldn't work with duplicates when two or three were back to back, and * wasn't the solution, either.
Also to note, this 'rounds up', so if there are three back to back, two will remain (3 / 2 = 1.5, rounded up to 2).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Replacing with multiple occurrences.
by physi (Friar) on May 08, 2003 at 16:32 UTC | |
|
Re: Replacing with multiple occurrences.
by Skeeve (Parson) on May 09, 2003 at 06:37 UTC |