fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. import java.util.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  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. final String regex = "(?:\\.*([A-Z0-9]+)|\\G(?!\\A))(?:\\h+\\|\\h+|$)";
  14. final String string = "ABCDEFG | .ABCDEF | ..ABCDE | ...ABCD | ....ABC | .....AB";
  15.  
  16. final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  17. final Matcher matcher = pattern.matcher(string);
  18.  
  19. while (matcher.find()) {
  20. if (matcher.group(1) != null) {
  21. System.out.println(matcher.group(1));
  22. }
  23. }
  24. }
  25. }
Success #stdin #stdout 0.05s 27996KB
stdin
Standard input is empty
stdout
ABCDEFG
ABCDEF
ABCDE
ABCD
ABC
AB