3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '# (811) (1485) [2756] {29} [555] {15} # (811) (1476) {20} {15} (1485) [196] [2441] # (911) (619) {19} (1476) [2765] [2752] {21}'; echo preg_replace_callback('~ {(?!(?:19|20)})(\d+)}(?! *$)| *$~m', function($m) { static $rep = ''; $rep .= $m[0]; if ( !isset($m[1]) && [$ret, $rep] = [$rep, ''] ) return $ret; }, $str);

preferences:
23.61 ms | 404 KiB | 5 Q