fork download
  1. <?php
  2.  
  3. $re = '~(?:([^][]*)\b\[|(?!^)\G)\s*(\w+(?:-\w+)*(?:=(["\'])?[^\]]*?\3)?)~';
  4. $str = "Loader[data-prop data-attr=\"value\" more-here='data' and-one-more=\"\"]";
  5. preg_match_all($re, $str, $matches);
  6. $arr = array();
  7. for ($i = 0; $i < count($matches); $i++) {
  8. if ($i != 0) {
  9. $arr = array_merge(array_filter($matches[$i]),$arr);
  10. }
  11. }
  12. print_r(preg_grep('~\A(?![\'"]\z)~', $arr));
  13.  
Success #stdin #stdout 0.03s 52472KB
stdin
Standard input is empty
stdout
Array
(
    [3] => data-prop
    [4] => data-attr="value"
    [5] => more-here='data'
    [6] => and-one-more=""
    [7] => Loader
)