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 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(51) { [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(2) { [0]=> string(1) "t" [1]=> string(1) "t" } [12]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [13]=> array(5) { [0]=> string(10) "="_parent"" [1]=> string(0) "" [2]=> string(10) "="_parent"" [3]=> string(1) """ [4]=> string(7) "_parent" } [14]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [15]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [16]=> array(2) { [0]=> string(1) "d" [1]=> string(1) "d" } [17]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [18]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "a" } [19]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [20]=> array(2) { [0]=> string(1) "t" [1]=> string(1) "t" } [21]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [22]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "a" } [23]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [24]=> array(2) { [0]=> string(1) "-" [1]=> string(1) "-" } [25]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [26]=> array(2) { [0]=> string(1) "f" [1]=> string(1) "f" } [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(1) "o" [1]=> string(1) "o" } [31]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [32]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [33]=> array(2) { [0]=> string(1) "d" [1]=> string(1) "d" } [34]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [35]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "a" } [36]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [37]=> array(2) { [0]=> string(1) "t" [1]=> string(1) "t" } [38]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [39]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "a" } [40]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [41]=> array(2) { [0]=> string(1) "-" [1]=> string(1) "-" } [42]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [43]=> array(2) { [0]=> string(1) "b" [1]=> string(1) "b" } [44]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [45]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "a" } [46]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [47]=> array(2) { [0]=> string(1) "r" [1]=> string(1) "r" } [48]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } [49]=> array(5) { [0]=> string(6) "="baz"" [1]=> string(0) "" [2]=> string(6) "="baz"" [3]=> string(1) """ [4]=> string(3) "baz" } [50]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } }