How do I remove duplicate characters and keep the unique one only in Perl?
问题 How do I remove duplicate characters and keep the unique one only. For example, my input is: EFUAHUU UUUEUUUUH UJUJHHACDEFUCU Expected output is: EFUAH UEH UJHACDEF I came across perl -pe's/$1//g while/(.).*\/' which is wonderful but it is removing even the single occurrence of the character in output. 回答1: This can be done using positive lookahead : perl -pe 's/(.)(?=.*?\1)//g' FILE_NAME The regex used is: (.)(?=.*?\1) . : to match any char. first () : remember the matched single char. (?=..