Syntactic Confectionery Delight | |
PerlMonks |
Re: Remove repeated characters from a stringby knew (Monk) |
on May 13, 2004 at 14:49 UTC ( [id://353087]=note: print w/replies, xml ) | Need Help?? |
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
In Section
Seekers of Perl Wisdom
|
|