I am doing a basic CLI to manage server instances and it streams. Some greyboxtesting show up some problems: I am not parsing the input right.
The commands syntax is as follows: command [arg1,...]
After some searching I came up with an idea: Using regular expression somehow.
Now the thing is, to start in instance, the sytanx is as follows: start {instancename} {path to file}
where {path to file}
must be quoted, because of spaces in pathnames.
Currently I am splitting it when acepting the input and just joining the array in my command class. That isn't very nice since it breaks the pattern of args[]
How must my regex syntax look like to split my string whatever here "is"
to have:
- Single words
- Quoted text is 1 array entry
The check if the single arguments are valid happens in a valiator interface.
I have this as a reference what i need.
I dont want to look "blocked" or that I didn't used my brain to solve this, so I will add my ideas how to do this too (I am just unable to find out the regex myself.. sorry):
- Split by char " " (Space)
- Don't apply this rule to text between quotes (Maybe single OR double)
Is it even possible that I can parse the input so my 3 value is acutaly my path (without using any quotes when typed in)?
Edit:
To mention the soltion of @Andreas, I add the link of the solution that worked well!