The title of the question is a bit wonky but can be better explained with an example.
I am attempting to make a custom command-line for user input. I take in the user's input as a string but I would like to parse the commands arguments into an array. I am able to use .split(" ")
to split up the string at all the spaces but would like to keep anything between quotes, square brackets, and curly brackets as one argument (brackets keep them inside of argument). Example:
let input = "command arg 1 \"arg 2\" [arg 3] {arg 4}";
let arguments = input.parseArgs(); // Returns a list of: ["arg", "1", "arg 2", "[arg 3]", "{arg 4}"]
I have attempted to use regex to search through the command but I feel that there is an easier way.
Summary, take all arguments of a command and place them into an array but include strings as one argument and brackets as a full argument.