3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "foo (20/50) bar () baz (11/30)"; $pattern = '~\G(?<title>\S+)\h+\((?:(?<number>\d+)/\d+)?\)(?:\s|$)~'; preg_match_all($pattern, $str, $matches, PREG_SET_ORDER, 0); $matches = array_reduce($matches, function($carry, $item) { $carry[] = [ "title" => $item["title"], "number" => array_key_exists("number", $item) ? $item["number"] : 0 ]; return $carry; }); print_r($matches);

preferences:
29.71 ms | 406 KiB | 5 Q