in reply to How to remove all repeating characters in a string in place

This substitution will give the results you want.

$str =~ s/(.)\1+//g;

Update: Redid after seeing mr_ron's post. (was originally s/((.)\2+)//g;)

Replies are listed 'Best First'.
Re^2: How to remove all repeating characters in a string in place
by punitpawar (Sexton) on Jan 31, 2016 at 15:48 UTC
    Thanks a lot for the help.
    Yes this works , I was trying to do s/(\w)$1+//;
    I forgot that $1 is not defined inside a pattern as it is being matched and hence I should be using \1 instead
      ... I was trying to do s/(\w)$1+//; ...

      Had you given this information in addition to the info you gave in the OP, it would have been most helpful in addressing your problem. Please always try to give some indication of what you have tried, how it failed, what you expected, etc. Please see How do I post a question effectively?.


      Give a man a fish:  <%-{-{-{-<