You must tokenize a single line representing a shell-like command into its argument list, following these exact rules:
') is taken completely literally: no character inside it, including a backslash, is special. The segment ends at the very next '.") is mostly literal, except for two special escape sequences: a backslash immediately followed by a double-quote character becomes one literal double-quote character, and a backslash immediately followed by another backslash character becomes one literal backslash character. A backslash followed by any other character inside double quotes (including at the position right before the closing quote, if that combination doesn't match one of the two escapes above) has no special meaning — both characters are kept exactly as-is. The segment ends at the next double-quote that was not just consumed as part of one of those two escapes.ab"cd"ef is one argument, and 'a'"b"c is one argument).Print the resulting arguments, one per line, in order. If the line contains zero arguments (for example it is empty or made up only of spaces), print nothing.
Line 1: the command line to tokenize (may be empty).
Each resulting argument on its own line, in order. Zero lines of output if there are zero arguments.
Example 1
Input
deploy "prod env" v2
Expected
deploy prod env v2
Explanation
Three arguments: `deploy`, the quoted `prod env` (kept together as one argument because the space is inside double quotes), and `v2`.
Example 2
Input
set\ name 'hello world' end
Expected
set name hello world end
Explanation
The backslash before the space in `set\ name` escapes it, so `set` and `name` merge into ONE argument `set name`; then the single-quoted `hello world` is another argument; then `end`. Three arguments total.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →