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); 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 [1] => -"exclude phrase" [2] => "phrase 1" [3] => keyword [4] => +k:v [5] => -k2:v2 [6] => + [7] => q [8] => kw:2 ) [flag] => Array ( [0] => - [1] => - [2] => [3] => [4] => + [5] => - [6] => [7] => [8] => ) [1] => Array ( [0] => - [1] => - [2] => [3] => [4] => + [5] => - [6] => [7] => [8] => ) [key] => Array ( [0] => [1] => [2] => [3] => [4] => k: [5] => k2: [6] => [7] => [8] => kw: ) [2] => Array ( [0] => [1] => [2] => [3] => [4] => k: [5] => k2: [6] => [7] => [8] => kw: ) [value] => Array ( [0] => exclude [1] => "exclude phrase" [2] => "phrase 1" [3] => keyword [4] => v [5] => v2 [6] => + [7] => q [8] => 2 ) [3] => Array ( [0] => exclude [1] => "exclude phrase" [2] => "phrase 1" [3] => keyword [4] => v [5] => v2 [6] => + [7] => q [8] => 2 ) )
Output for 4.3.0 - 4.3.2
Array ( [0] => Array ( [0] => -exclude [1] => -"exclude phrase" [2] => "phrase 1" [3] => keyword [4] => +k:v [5] => -k2:v2 [6] => + [7] => q [8] => kw:2 ) [1] => Array ( [0] => - [1] => - [2] => [3] => [4] => + [5] => - [6] => [7] => [8] => ) [2] => Array ( [0] => [1] => [2] => [3] => [4] => k: [5] => k2: [6] => [7] => [8] => kw: ) [3] => Array ( [0] => exclude [1] => "exclude phrase" [2] => "phrase 1" [3] => keyword [4] => v [5] => v2 [6] => + [7] => q [8] => 2 ) )