3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parseQuoteAware(string $commandLine) : array{ $args = []; preg_match_all('/"((?:\\\\.|[^\\\\"])*)"|(\S+)/u', $commandLine, $matches); foreach($matches[0] as $k => $_){ for($i = 1; $i <= 2; ++$i){ if($matches[$i][$k] !== ""){ $match = $matches[$i][$k]; $args[] = preg_replace('/\\\\([\\\\"])/u', '$1', $match) ?? throw new AssumptionFailedError(preg_last_error_msg()); break; } } } return $args; } $cmdLine = '/tellraw @a[name="Arie1906", c=1] "quoted \"string\"" {"rawtext": [{"text":"§bI am blue"}]}'; var_dump(parseQuoteAware($cmdLine));
Output for 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array(8) { [0]=> string(8) "/tellraw" [1]=> string(19) "@a[name="Arie1906"," [2]=> string(4) "c=1]" [3]=> string(15) "quoted "string"" [4]=> string(11) "{"rawtext":" [5]=> string(14) "[{"text":"§bI" [6]=> string(2) "am" [7]=> string(8) "blue"}]}" }

preferences:
58.7 ms | 858 KiB | 4 Q