3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $query = "-exclude -\"exclude phrase\" \"phrase 1\" keyword +k:v -k2:v2 +\"q kw:2"; $ATOM_REGEX = '"[^"]+"|[^"\s]+'; preg_match_all("/(?P<flag>[-+])?(?P<key>$ATOM_REGEX:)?(?P<value>$ATOM_REGEX)/", $query, $match, PREG_SET_ORDER); print_r($match);
Output for 4.3.3 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => Array ( [0] => -exclude [flag] => - [1] => - [key] => [2] => [value] => exclude [3] => exclude ) [1] => Array ( [0] => -"exclude phrase" [flag] => - [1] => - [key] => [2] => [value] => "exclude phrase" [3] => "exclude phrase" ) [2] => Array ( [0] => "phrase 1" [flag] => [1] => [key] => [2] => [value] => "phrase 1" [3] => "phrase 1" ) [3] => Array ( [0] => keyword [flag] => [1] => [key] => [2] => [value] => keyword [3] => keyword ) [4] => Array ( [0] => +k:v [flag] => + [1] => + [key] => k: [2] => k: [value] => v [3] => v ) [5] => Array ( [0] => -k2:v2 [flag] => - [1] => - [key] => k2: [2] => k2: [value] => v2 [3] => v2 ) [6] => Array ( [0] => + [flag] => [1] => [key] => [2] => [value] => + [3] => + ) [7] => Array ( [0] => q [flag] => [1] => [key] => [2] => [value] => q [3] => q ) [8] => Array ( [0] => kw:2 [flag] => [1] => [key] => kw: [2] => kw: [value] => 2 [3] => 2 ) )
Output for 4.3.0 - 4.3.2
Array ( [0] => Array ( [0] => -exclude [1] => - [2] => [3] => exclude ) [1] => Array ( [0] => -"exclude phrase" [1] => - [2] => [3] => "exclude phrase" ) [2] => Array ( [0] => "phrase 1" [1] => [2] => [3] => "phrase 1" ) [3] => Array ( [0] => keyword [1] => [2] => [3] => keyword ) [4] => Array ( [0] => +k:v [1] => + [2] => k: [3] => v ) [5] => Array ( [0] => -k2:v2 [1] => - [2] => k2: [3] => v2 ) [6] => Array ( [0] => + [1] => [2] => [3] => + ) [7] => Array ( [0] => q [1] => [2] => [3] => q ) [8] => Array ( [0] => kw:2 [1] => [2] => kw: [3] => 2 ) )