0

I need a regex string that remove the duplicated characters that occurs more than 1 time.

for example :

eve -> e and v
eev -> e and v

i found one that like this : (.)(?=\\1)

that regex can remove duplicated characters that adjacent like : eev -> e and v

but that regex can not remove the second e after v in "eve" word.

XtremeBaumer
  • 6,275
  • 3
  • 19
  • 65

1 Answers1

0

If you are using Java 8 you can use :

String result = str.chars()
        .mapToObj(c -> String.valueOf((char) c))
        .distinct()
        .collect(Collectors.joining());

I/O

eve         -> ev
eev         -> ev
evevvveeeve -> ev
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140