Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.regex.Pattern;
- public class Main {
- static String commandWithArgument = "(remove|add|add_if_max|remove_greater)";
- static String command = "(info|show|remove_first|exit|help)";
- static String argument = "\\{( *?\"(id|name|actions|professions|location)\" *?: *?[\"\\[0-9].*?[\"\\]]? *?,?)+\\}";
- static String regexp = "(" + commandWithArgument + " " + argument + ")|" +
- "(import .*)|" +
- command;
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Pattern pattern = Pattern.compile(regexp);
- while (true) {
- String line = scanner.nextLine();
- System.out.println(pattern.matcher(line).matches());
- }
- }
- /*
- remove { "id":"1", "name":"Java", "actions":[{"id":"2", "actionName":"actor"}], "profession":[{"id":"3", "professionName":"police"}], "location":"FOREST"}
- remove \{ *?(id|name|actions|professions|location) *?: *?["\[0-9].*?["\]0-9] *?,?\}
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement