fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String data = "syntax = \"proto3\";\r\n" +
  13. "package grpc;\r\n" +
  14. "\r\n" +
  15. "import \"envoyproxy/protoc-gen-validate/validate/validate.proto\";\r\n" +
  16. "import \"google/api/annotations.proto\";\r\n" +
  17. "import \"google/protobuf/wrappers.proto\";\r\n" +
  18. "import \"protoc-gen-swagger/options/annotations.proto\";\r\n" +
  19. "\r\n" +
  20. "message Acc {\r\n" +
  21. " message AccErr {\r\n" +
  22. " enum Enum {\r\n" +
  23. " UNKNOWN = 0;\r\n" +
  24. " CASH = 1;\r\n" +
  25. " }\r\n" +
  26. " }\r\n" +
  27. " string account_id = 1;\r\n" +
  28. " string name = 3;\r\n" +
  29. " string account_type = 4;\r\n" +
  30. "}\r\n" +
  31. "\r\n" +
  32. "message Name {\r\n" +
  33. " string firstname = 1;\r\n" +
  34. " string lastname = 2;\r\n" +
  35. "}";
  36. String[] messages = data.replaceAll("(?sm)\\A.*?(?=^message)", "").split("\\R+(?=message)");
  37. System.out.println("Found " + messages.length + " messages: " + Arrays.toString(messages));
  38. }
  39. }
Success #stdin #stdout 0.15s 50484KB
stdin
Standard input is empty
stdout
Found 2 messages: [message Acc {
    message AccErr {
        enum Enum {
            UNKNOWN = 0;
            CASH = 1;
        }
    }
    string account_id = 1;
    string name = 3;
    string account_type = 4;
}, message Name {
    string firstname = 1;
    string lastname = 2;
}]