3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'This is the string number 123-45-6789-0 which contains 12-34567.'; echo preg_replace_callback('~\d+(?:-\d+)+~', function($m) { return implode('-', array_reverse(explode('-', $m[0]))); } ,$str);

preferences:
49.08 ms | 407 KiB | 5 Q