3v4l.org

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

preferences:
56.41 ms | 406 KiB | 5 Q