php regex how to remove duplicate charactors and make every charactor unique in string
How should one use
preg_replace() to replace a string from 'aabbaacc' to 'abc'?
Currently, my code uses
preg_replace() can achieve this also, but I don't know how.
Thank you for your help.
A regex that seems to work for me is
/(.)(?=.*?\1)/. Please test it for yourself here:
I've also tested it with
preg_replace('/(.)(?=.*?\1)/', '', 'aaabbbabc')which returns the expected
Hope this helps :)
This is the closest I got. However, it's basically a copy of : How do I remove duplicate characters and keep the unique one only in Perl?
Unfortunately, it does not keep the string in the same order. I don't know if that is important to you or not.
or this with out Regex