3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test = <<<URLS https://example.com/cost-center/sub-one/sub-two/article-3/ https://example.com/cost-center/sub-one/sub-three/article-4 https://example.com/cost-center/sub-1/sub-two/sub-three/article-5/ 'https://example.com/cost-center/sub-one/sub-two/article-3/' 'https://example.com/cost-center/sub-1/sub-two/sub-three/article-5' "https://example.com/cost-center/sub-one/sub-three/article-4" "https://example.com/cost-center/sub-1/sub-two/sub-three/article-5/" URLS; echo preg_replace('#https://[^/]+/cost-center/\K([^/\s]+/)+(?=article)#', 'test/', $test);

preferences:
73.87 ms | 404 KiB | 5 Q