0

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!

Community
  • 1
  • 1
Isfirs
  • 124
  • 1
  • 12
  • escape the double quotes as `\"` – rock321987 Apr 13 '16 at 08:03
  • Show some [mcve](http://stackoverflow.com/help/mcve) to make it easier for us to help you. – dambros Apr 13 '16 at 08:07
  • A simple Google search for `java quoted string parsing` came up with that duplicate. – Andreas Apr 13 '16 at 08:10
  • Ok, I searched for various combination, but I did not manage to find [this](http://stackoverflow.com/questions/7804335/split-string-on-spaces-in-java-except-if-between-quotes-i-e-treat-hello-wor) one. That did [GREAT](https://gist.github.com/Isfirs/1665bf03dd2ae723bb4d719df17e410e) !!! Thank you! – Isfirs Apr 13 '16 at 09:24

0 Answers0