I'm trying to create a regex that gives me a few combination pairs from an input that I'm interested in.
If I had the following input...
"pppeeeople"
I would like to create the following permutations...
people, ppeeople, peeople, ppeople.
I can currently create 'people' and 'ppeeople' with the following two REGEXs where the input word is 'pppeeeople'.
String temp = word.replaceAll("(.)\\1{2,}", "$1$1"); //result ppeeople
String temp2 = word.replaceAll("(.)\\1{1,}", "$1"); //result people
However I would like to be able to generate a REGEX that can also grab the word with 1 set of two consective letters, such as 'ppeople', then another REGEX that can skip the first inputed double character sequence and produce 'peeople' and so forth. The basic idea is to get all permutations of the word that contain a two consecutive characters.
Is this possible with a REGEX or should I just use a loop and StringBuilder into a list?
This is close, but it produces out of bounds index errors and I would still have to remove duplicates from the ArrayList repeats I'm adding it to.
int index = temp.length();
for (int i = 0; i < index; i++) {
System.out.println("Index" + i + ": " + temp);
if(temp.charAt(i) == temp.charAt(i+1)) {
StringBuilder sb = new StringBuilder(temp);
repeats.add(temp);
sb.deleteCharAt(i);
temp = sb.toString();
}
}