3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string="localhost/uploads/images/photo.jpg"; $string2="localhost/uploads/images/photo_thumb.jpg"; $replacement="$1/$2_thumb.$3"; $pattern= '/([\w+\/]*)(?=\/)\/([\w]+(?<!_thumb))\.(\w+)/i'; echo preg_replace($pattern, $replacement, $string); echo "\n\r"; echo preg_replace($pattern, $replacement, $string2);

preferences:
26.57 ms | 405 KiB | 5 Q