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);
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
# (811) (1485) [2756] [555] {15} {29} # (811) (1476) {20} (1485) [196] [2441] {15} # (911) (619) {19} (1476) [2765] [2752] {21}

preferences:
116.47 ms | 407 KiB | 5 Q