3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $attrPattern = '/([a-z0-9-]*)(=(["\']??)([^"\']*?)\\3)??/siU'; $attr = 'target="_parent" data-foo data-bar="baz"'; preg_match_all($attrPattern, $attr, $matches, PREG_SET_ORDER); var_dump($matches);
Output for 4.3.0 - 7.1.0
array(47) { [0]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [1]=> array(2) { [0]=> string(1) "t" [1]=> string(1) "t" } [2]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [3]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "a" } [4]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [5]=> array(2) { [0]=> string(1) "r" [1]=> string(1) "r" } [6]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [7]=> array(2) { [0]=> string(1) "g" [1]=> string(1) "g" } [8]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [9]=> array(2) { [0]=> string(1) "e" [1]=> string(1) "e" } [10]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [11]=> array(5) { [0]=> string(11) "t="_parent"" [1]=> string(1) "t" [2]=> string(10) "="_parent"" [3]=> string(1) """ [4]=> string(7) "_parent" } [12]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [13]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [14]=> array(2) { [0]=> string(1) "d" [1]=> string(1) "d" } [15]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [16]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "a" } [17]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [18]=> array(2) { [0]=> string(1) "t" [1]=> string(1) "t" } [19]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [20]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "a" } [21]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [22]=> array(2) { [0]=> string(1) "-" [1]=> string(1) "-" } [23]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [24]=> array(2) { [0]=> string(1) "f" [1]=> string(1) "f" } [25]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [26]=> array(2) { [0]=> string(1) "o" [1]=> string(1) "o" } [27]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [28]=> array(2) { [0]=> string(1) "o" [1]=> string(1) "o" } [29]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [30]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [31]=> array(2) { [0]=> string(1) "d" [1]=> string(1) "d" } [32]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [33]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "a" } [34]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [35]=> array(2) { [0]=> string(1) "t" [1]=> string(1) "t" } [36]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [37]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "a" } [38]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [39]=> array(2) { [0]=> string(1) "-" [1]=> string(1) "-" } [40]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [41]=> array(2) { [0]=> string(1) "b" [1]=> string(1) "b" } [42]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [43]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "a" } [44]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [45]=> array(5) { [0]=> string(7) "r="baz"" [1]=> string(1) "r" [2]=> string(6) "="baz"" [3]=> string(1) """ [4]=> string(3) "baz" } [46]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } }