punitpawar has asked for the wisdom of the Perl Monks concerning the following question:
So I did try something like this below , but it requires me to do the replacement repeatedly to get rid of all repeating charactersInPut : $str = "abcdefghiaabccdjklm"; OutPut : $str="efghijklm";
Original String : my $str = "abcdeffghijkllmnoppqestqaserb"; 1st iteration : $str =~ s/(\w)(.*)\1/$2/g; Output : bcdeffghijkllmnoppqestqserb 2nd Iteration : $str =~ s/(\w)(.*)\1/$2/g; OutPut : cdeffghijkllmnoppqestqser 3rd Iteration : $str =~ s/(\w)(.*)\1/$2/g; OutPut : cdffghijkllmnoppqestqsr 4th Iteration : Gets rid of consecutive elements $str =~ s/(\w)(.*)\1/$2/g; OutPut: cdghijkmnoestsr
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to remove duplicate characters in a string in place
by poj (Abbot) on Feb 20, 2016 at 17:49 UTC | |
|
Re: How to remove duplicate characters in a string in place
by toolic (Bishop) on Feb 20, 2016 at 17:37 UTC | |
|
Re: How to remove duplicate characters in a string in place
by duelafn (Parson) on Feb 20, 2016 at 17:55 UTC | |
|
Re: How to remove duplicate characters in a string in place
by hdb (Monsignor) on Feb 20, 2016 at 17:58 UTC | |
|
Re: How to remove duplicate characters in a string in place -- oneliner
by Discipulus (Canon) on Feb 20, 2016 at 21:22 UTC | |
|
Re: How to remove duplicate characters in a string in place
by Anonymous Monk on Feb 20, 2016 at 19:30 UTC | |
|
Re: How to remove duplicate characters in a string in place
by kcott (Archbishop) on Feb 22, 2016 at 06:43 UTC | |
|
Re: How to remove duplicate characters in a string in place
by tybalt89 (Monsignor) on Apr 03, 2017 at 17:28 UTC |