fork download
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. class Main
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. Pattern pattern = Pattern.compile("(?<!(.)(?=\\1))([^raol1c])\\2(?!\\2)");
  12. System.out.println("hhh:");
  13. Matcher matcher = pattern.matcher("hhh");
  14. while (matcher.find()) {
  15. System.out.print("Start index: " + matcher.start());
  16. System.out.print(" End index: " + matcher.end() + " ");
  17. System.out.println(matcher.group());
  18. }
  19. System.out.println("hh:");
  20. matcher = pattern.matcher("hh");
  21. while (matcher.find()) {
  22. System.out.print("Start index: " + matcher.start());
  23. System.out.print(" End index: " + matcher.end() + " ");
  24. System.out.println(matcher.group());
  25. }
  26. System.out.println("ahh:");
  27. matcher = pattern.matcher("ahh");
  28. while (matcher.find()) {
  29. System.out.print("Start index: " + matcher.start());
  30. System.out.print(" End index: " + matcher.end() + " ");
  31. System.out.println(matcher.group());
  32. }
  33. System.out.println("hha:");
  34. matcher = pattern.matcher("hha");
  35. while (matcher.find()) {
  36. System.out.print("Start index: " + matcher.start());
  37. System.out.print(" End index: " + matcher.end() + " ");
  38. System.out.println(matcher.group());
  39. }
  40. System.out.println("ahhahhhahha:");
  41. matcher = pattern.matcher("ahhahhhahha");
  42. while (matcher.find()) {
  43. System.out.print("Start index: " + matcher.start());
  44. System.out.print(" End index: " + matcher.end() + " ");
  45. System.out.println(matcher.group());
  46. }
  47. }
  48. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
hhh:
hh:
Start index: 0 End index: 2 hh
ahh:
Start index: 1 End index: 3 hh
hha:
Start index: 0 End index: 2 hh
ahhahhhahha:
Start index: 1 End index: 3 hh
Start index: 8 End index: 10 hh