import java.util.Scanner;
public class redigetajs {
public static void main(String args[]){
Scanner scan= new Scanner(System.in);
System.out.println("Input text!");
String teksts= scan.nextLine();
System.out.println("text after change!");
System.out.println(teksts.replaceAll("(.)\\1{1,}", "$1"));
}
}
Asked
Active
Viewed 155 times
3

mahesh
- 1,311
- 1
- 13
- 26

user2908920
- 33
- 6
-
1`{1,}` is the same as `+`. [Check the SO regex reference](http://stackoverflow.com/q/22937618) – HamZa May 06 '14 at 11:35
3 Answers
3
It matches sequences of identical characters and collapses them into only one occurrence.
Example: "aaaaabcccdd"
-> "abcd"

cadrian
- 7,332
- 2
- 33
- 42
1
Suexpression duplicate a group character and removed:
(.)
- group, also referenced as$1
\\1
- subexpression followed it{1,}
- to repeat one or more times

Roman C
- 49,761
- 33
- 66
- 176