fork download
  1. <?php
  2.  
  3. $re = '/(?:\[foobar\b|(?!^)\G)\s+\K(?<key>[^=]+)="(?<val>[^"]*)"(?=\s+[^=]+="|])/';
  4. $str = "[foobar a=\"b\" c=\"d\" f=\"g\"]";
  5.  
  6. preg_match_all($re, $str, $matches);
  7. print_r(array_combine($matches["key"], $matches["val"]));
Success #stdin #stdout 0.02s 52480KB
stdin
Standard input is empty
stdout
Array
(
    [a] => b
    [c] => d
    [f] => g
)