fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String text = String.join("\n",
  11. "ERROR java.lang.NullPointerException: Sample Java Logback Exception",
  12. "at Sample.errorLevel3(Sample.java:35)",
  13. "at Sample.errorLevel4(Sample.java:34)",
  14. "at Sample.errorLevel5(Sample.java:30)",
  15. "at Sample.errorLevel6(Sample.java:3)"
  16. );
  17. String pattern = "(?:^.*\\s([^:,\\s]+):\\s+([^:\\n]+)|\\G(?!\\A))\\s*at\\s+(\\S+)\\((\\w+\\.\\w+):(\\d+)\\)$";
  18. Pattern regex = Pattern.compile(pattern, Pattern.MULTILINE);
  19. Matcher m = regex.matcher(text);
  20. int matchNum = 0;
  21.  
  22.  
  23. //Loop matches
  24. while (m.find())
  25. {
  26. matchNum++;
  27.  
  28. // Loop groups
  29. for (int i = 1; i <= m.groupCount(); i++)
  30. {
  31. if (m.group(i) != null) {
  32. System.out.println("Match " + matchNum + " - Group " + i + ": " + m.group(i));
  33. }
  34. }
  35. }
  36. }
  37. }
  38.  
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
Match 1 - Group 1: java.lang.NullPointerException
Match 1 - Group 2: Sample Java Logback Exception
Match 1 - Group 3: Sample.errorLevel3
Match 1 - Group 4: Sample.java
Match 1 - Group 5: 35
Match 2 - Group 3: Sample.errorLevel4
Match 2 - Group 4: Sample.java
Match 2 - Group 5: 34
Match 3 - Group 3: Sample.errorLevel5
Match 3 - Group 4: Sample.java
Match 3 - Group 5: 30
Match 4 - Group 3: Sample.errorLevel6
Match 4 - Group 4: Sample.java
Match 4 - Group 5: 3