I have a string
that represents a command. Each command can be a different length. For example here are some commands
showmessage "hello im the message"
exit
showmessage "im the message" "im the title"
playsound /path/to/sound/file
My function takes a string
that has the whole command and currently splits the string
into a string
array using split("\\s+")
.
However this splits the command at every whitespace. What I need to do is split the command at each space UNLESS something in the command started with "
and ends with "
. In this case I'd need to split the string
so that the string
array contains a string
that is the whole part of the command that is in quotes.
So if the input command was:
showmessage "the message"
the split string
array would contain the strings
:
showmessage
, "the message"
and if the command was:
showmessage the message
the split array would contain:
showmessage
, the
, message
Is there a way to do this with regexes?