Java tutorial
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { String word = "77933211"; Pattern pattern = Pattern.compile("(\\d)\\1"); Matcher matcher = pattern.matcher(word); word = matcher.replaceAll("$1"); System.out.println(word); } }