in reply to Remove repeated characters from a string
This bit of code will do the job:
$string =~ s/(.)\1/$1/gAlternatively, if you want to ignore case when comparing, you could use:
$string =~ s/(.)\1/$1/giAnd finally, if you wanted to trim any number of duplicates down to a single letter, this would work:
$string =~ s/(.)\1+/$1/gi
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re:^2 Remove repeated characters from a string
by Anonymous Monk on May 13, 2004 at 14:55 UTC | |
by knew (Monk) on May 13, 2004 at 15:12 UTC | |
by aramisf (Beadle) on Apr 10, 2014 at 18:24 UTC | |
by EdwardG (Vicar) on May 13, 2004 at 14:59 UTC |