Basically, I need to split the string like
"one quoted argument" those are separate arguments "but not \"this one\""
to get in result the list of arguments
- "one quoted argument"
- those
- are
- separate
- "but not \"this one\""
This regex "(\"|[^"])*"|[^ ]+
nearly does the job but the issue is that regular expression always (at least in java) tries to match the longest string possible.
In consequence, when I apply the regex to a string that starts and ends with a quoted arguments, it matches the whole string and does not create a group for each argument.
Is there a way to tweak this regex or the matcher or the pattern or whatever to handle that?
Note: don't tell me I could use GetOpt
or CommandLine.parse
or anything else similar.
My concern is about pure java regex (if possible but I doubt it...).