fork download
  1. <?php
  2.  
  3. $str = 'travelling the world tag:"aussie guy" country:Australia';
  4.  
  5. preg_match_all('~(\w+):"?\K((?(?<=")[^"]*|\w*))~', $str, $matches);
  6.  
  7. print_r($matches[1]);
  8. print_r($matches[2]);
  9.  
  10. ?>
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
Array
(
    [0] => tag
    [1] => country
)
Array
(
    [0] => aussie guy
    [1] => Australia
)