in reply to Remove repeated characters from a string

If you want to remove all duplicate letters, not just adjacent ones, this does it without any loops (external to the regex engine).

print $s; abacadaeafabacadaeafabacadaeafabacadaeafabacadaeafabacadaeaf $s =~ s[(.)(?=.*?\1)][]g; print $s; bcdeaf

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re:^2 Remove repeated characters from a string
by ysth (Canon) on May 13, 2004 at 16:23 UTC
    Don't know if you wrote this before or after the clarification; but this removes all but the last, where it seems all but the first is the desired behavior.

      Your right, I missed the clarification. I guess you could do a scalar reverse before and after, but that kinda takes the shine off the solution.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail