fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13.  
  14.  
  15. final String regex = "a(b|(bc|(bcd|(bcde|bcdef))))?$";
  16. String string = "asdjb|ak.fvajfabcdefabcdefabcdefabc";
  17.  
  18. final Pattern pattern = Pattern.compile(regex);
  19. Matcher matcher = pattern.matcher(string);
  20. int length = 0;
  21. while (matcher.find()) {
  22. System.out.println("Full match: " + matcher.group(0));
  23. length += matcher.group(0).length();
  24. // System.out.println(string.substring(0, string.length()-length));
  25. // string = string.substring(0, string.length());
  26. // System.out.println(string);
  27. matcher = pattern.matcher(string.substring(0, string.length()- length));
  28. }
  29. System.out.println(string.substring(0, string.length()- length));
  30. }
  31. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
Full match: abc
Full match: abcdef
Full match: abcdef
Full match: abcdef
asdjb|ak.fvajf