3v4l.org

run code in 500+ PHP versions simultaneously
<?php $strings = [ 'this/is/the/path/to/my/fileA.php', 'this/could/also/be/the/path/to/my/fileB.php', 'another/example/of/a/long/address/which/is/a/path/to/my/fileC.php', ]; var_export( preg_replace( '~.*((?:/[^/]*){4}$)~', '$1', $strings ) );
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
array ( 0 => '/path/to/my/fileA.php', 1 => '/path/to/my/fileB.php', 2 => '/path/to/my/fileC.php', )

preferences:
93.06 ms | 1141 KiB | 4 Q