@@ -0,0 +1,832 @@
+import java.util.Scanner;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Apublic class DuplicateWords %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        String regex = %22%5C%5Cb(%5C%5Cw+)(?:%5C%5CW+%5C%5C1%5C%5Cb)+%22;%0A        Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);%0A%0A        Scanner in = new Scanner(System.in);%0A        int numSentences = Integer.parseInt(in.nextLine());%0A%0A        while (numSentences-- %3E 0) %7B%0A            String input = in.nextLine();%0A%0A            Matcher m = p.matcher(input);%0A%0A            // Check for subsequences of input that match the compiled pattern%0A            while (m.find()) %7B%0A                input = input.replaceAll(m.group(), m.group(1));%0A            %7D%0A%0A            // Prints the modified sentence.%0A            System.out.println(input);%0A        %7D%0A%0A        in.close();%0A    %7D%0A%7D%0A

Solve java regex 2