Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Main {
  5. static String commandWithArgument = "(remove|add|add_if_max|remove_greater)";
  6. static String command = "(info|show|remove_first|exit|help)";
  7. static String argument = "\\{( *?\"(id|name|actions|professions|location)\" *?: *?[\"\\[0-9].*?[\"\\]]? *?,?)+\\}";
  8. static String regexp = "(" + commandWithArgument + " " + argument + ")|" +
  9. "(import .*)|" +
  10. command;
  11.  
  12.  
  13. public static void main(String[] args) {
  14. Scanner scanner = new Scanner(System.in);
  15. Pattern pattern = Pattern.compile(regexp);
  16. while (true) {
  17. String line = scanner.nextLine();
  18. System.out.println(pattern.matcher(line).matches());
  19. }
  20. }
  21.  
  22. /*
  23. remove { "id":"1", "name":"Java", "actions":[{"id":"2", "actionName":"actor"}], "profession":[{"id":"3", "professionName":"police"}], "location":"FOREST"}
  24. remove \{ *?(id|name|actions|professions|location) *?: *?["\[0-9].*?["\]0-9] *?,?\}
  25. */
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement