Parse a raw IRC message In the IRC protocol, raw messages look similar to this:

command arg1 arg2 :arg3 with spaces :arg4 with spaces :arg5


In a shell environment (e.g. bash), that would be equivalent to:

command arg1 arg2 "arg3 with spaces" "arg4 with spaces" arg5


The format specification is as follows:


Raw messages will only contain printable ASCII characters (ordinals 32-126).
Raw messages will start with a command, which will not contain any spaces.
Any number of arguments may follow a command. Arguments are delimited by one or more spaces followed by a colon (&lt;space&gt;: and &lt;space&gt;&lt;space&gt;: are both valid delimiters).


Any arguments that do not contain spaces may omit the colon from the delimiter so long as all previous arguments (if any) have omitted the colon.

Colons will not appear within arguments or commands.
Arguments will not begin with a space.


For example, these are all valid raw messages:

join #foo #bar #baz
msg person hi
msg #channel :hello world
help :how do I use IRC
foo bar :baz bip :abc def :ghi


These are all invalid raw messages:

error :n:o colons within arguments
error ::need spaces between colons
:error no colons in commands
error non-ASCII character Ω


Given a valid raw IRC message as input, output a list containing the command and the arguments, properly parsed.

Test Cases

"join #foo #bar #baz" -&gt; ["join", "#foo", "#bar", "#baz"]
"msg person hi" -&gt; ["msg", "person", "hi"]
"msg #channel :hello world" -&gt; ["msg", "#channel", "hello world"]
"help :how do I use IRC" -&gt; ["help", "how do I use IRC"]
foo bar :baz bip :abc def :ghi :xyz -&gt; ["foo", "bar", "baz bip", "abc def", "ghi", "xyz"]
PHP, 87 bytes
$a=($s=preg_split)(&quot;# +:#&quot;,$argv[1]);array_splice($a,0,1,$s(&quot;# +#&quot;,$a[0]));print_r($a);

The first regex splits the argument by one or more spaces followed by a colon.
The second regex splits the first element by one or more spaces with no colon.
array_splice replaces the first element with the result of the second preg_split.
print_r prints the resulting array.
function version for testing
$cases=[
    &quot;join #foo #bar #baz&quot; =&gt; [&quot;join&quot;, &quot;#foo&quot;, &quot;#bar&quot;, &quot;#baz&quot;],
    &quot;msg person hi&quot; =&gt; [&quot;msg&quot;, &quot;person&quot;, &quot;hi&quot;],
    &quot;msg #channel :hello world&quot; =&gt; [&quot;msg&quot;, &quot;#channel&quot;, &quot;hello world&quot;],
    &quot;help :how do I use IRC&quot; =&gt; [&quot;help&quot;, &quot;how do I use IRC&quot;],
    &quot;foo bar :baz bip :abc def :ghi :xyz&quot; =&gt; [&quot;foo&quot;, &quot;bar&quot;, &quot;baz bip&quot;, &quot;abc def&quot;, &quot;ghi&quot;, &quot;xyz&quot;],
];
function i($argv_1_){$a=($s=preg_split)(&quot;# +:#&quot;,$argv_1_);array_splice($a,0,1,$s(&quot;# +#&quot;,$a[0]));return $a;}
foreach($cases as$x=&gt;$e)
{
    $y=i($x);
    echo &quot;case '$x': ['&quot;,join(&quot;','&quot;,$y),'&quot;]: ',($y&lt;&gt;$e?&quot;FAIL. Expected: ['&quot;. join(&quot;','&quot;,$e).&quot;']&quot;:OK),&quot;\n&quot;;
}