in reply to Removing Adjacent Character Repititions

$string =~ s/(.)\1+/$1/g; # or... #$string =~ tr/A-Za-z0-9//s; $string =~ tr///sc; # update: use this instead

Note that if you use tr///, you have to specify every character you want to match.

Update: Ah, true. Thanks, BrowserUk.

bbfu
Black flowers blossum
Fearless on my breath

Replies are listed 'Best First'.
Re: Re: Removing Adjacent Character Repititions
by BrowserUk (Patriarch) on Jan 15, 2003 at 18:13 UTC

    If you want to remove contiguous duplicates of literally every character, you don't have to specify any characters with tr///s, you just add the /c option.

    $s = 'Ttthe Qqquiicccck brroooown fox' $s =~ tr///cs print $s Tthe Qquick brown fox

    Examine what is said, not who speaks.

    The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.