fork download
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) {
  9. ArrayList<String> sentences = new ArrayList<>();
  10. sentences.add("I heard the pastor sing live verses easily.");
  11. sentences.add("Deep episodes of Deep Space Nine came on the television only after the news.\n");
  12. sentences.add("Digital alarm clocks scare area children.");
  13. sentences.add("test string");
  14. sentences.add("this is string");
  15.  
  16. for (String sentence: sentences) {
  17. Pattern pattern = Pattern.compile("([a-zA-Z]+) \\1", Pattern.CASE_INSENSITIVE);
  18. Matcher matcher = pattern.matcher(sentence);
  19. String output = matcher.replaceAll("$1");
  20. System.out.println(output);
  21. }
  22. }
  23. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
I heard the pastor sing liverses easily.
Deepisodes of Deep Space Nine came on the televisionly after the news.

Digitalarm clockscarea children.
testring
this string