3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = "ABC01 ABC02 ABC03 ABC04 ABC05 ABC06 "; echo preg_replace( '/\R+(?=ABC04)/', ' - ', trim($text) );

preferences:
25.17 ms | 409 KiB | 6 Q