I have been trying to parse a command with regular expression in Java for a while but no success. The main issue I am having is that the delimiter is space and then I want to treat everything that is within a double quotes as an argument but what if one of these arg contains quotes within quotes. Here is the command and few examples:
my_command "regex or text" <"regex or text"|NA> <"text or regex"|NA> integer integer
Example1: my_command "Simple case" NA NA 2 3
Example2: my_command "This is it!" "[\",;']" "Really?" 3 5
Example3: my_command "Not so fast" NA "Another regex int the mix [\"a-zA-Z123]" 1 1
Basically parseCommand(String str) will take any of the above examples and return a List with the following values:
Example1: list[0] = "Simple Case", list[1] = NA, list[2] = NA, list[3] = "2", list[4] = "3"
Example2: list[0] = "This is it!", list[1] = "[\",;']", list[2] = NA, list[3] = "3", list[4] = "5"
Example3: list[0] = "Not so fast", list[1] = NA, list[2] = "Another regex int the mix [\"a-zA-Z123]" , list[3] = "1", list[4] = "1"
Thank you for your help in advance.