fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. String regex = "\\G\\[([^\\]\\[]*)]\\h+([^\\]\\[]+$)?";
  12. String string = "[2021-03-10 00:13:32.901] [DefaultDispatcher-worker-2 @coroutine#3] [DEBUG] [4231c006d9083a302fce59d5f0957226] [42c5ac3c0acfc68d] [GreeterImpl] Hello John";
  13.  
  14. Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  15. Matcher matcher = pattern.matcher(string);
  16.  
  17. while (matcher.find()) {
  18. for (int i = 1; i <= matcher.groupCount(); i++) {
  19. if (matcher.group(i) != null) {
  20. System.out.println(matcher.group(i));
  21. }
  22. }
  23. }
  24. }
  25. }
Success #stdin #stdout 0.12s 33844KB
stdin
Standard input is empty
stdout
2021-03-10 00:13:32.901
DefaultDispatcher-worker-2 @coroutine#3
DEBUG
4231c006d9083a302fce59d5f0957226
42c5ac3c0acfc68d
GreeterImpl
Hello John