3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = [ 'controller_123/method///', 'controller_123/method/', '% con $trol@$@ler_!123/me*thod////', ]; var_export( preg_replace( '~[^-\w/]+|/\K/+$~', '', $strings ) );

preferences:
30.07 ms | 405 KiB | 5 Q