3v4l.org

run code in 300+ PHP versions simultaneously
<?php $s = '[specs product="test" category="body"]'; $pattern = '/(?:\[(?=[^][]*])(\w+)|\G(?!^))\h+(\w+)="([^"]+)"/'; $strings = [ '[specs product="test" category="body"]', '[pricelist keyword="216"]', '[specs product="test2" category="network" key="value"]' ]; foreach($strings as $s) { if (preg_match_all($pattern, $s, $matches)) { unset($matches[0]); $matches = array_map('array_filter', $matches); print_r($matches); } }

preferences:
25.12 ms | 406 KiB | 5 Q