3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $test=array("abcd/abcd_.mp3", "abcd", "asdasd/abcd.mp3", "abcd.", "blahahbasdabcd"); $searchTerm = "abcd"; $replaceTerm = "XXXX"; foreach ($test as $t) echo "$t => " . preg_replace("/(". preg_quote($searchTerm) . "([^_.])|". preg_quote($searchTerm) . "$)/x", preg_quote($replaceTerm) . "\${2}", $t) . "\n";
Output for 4.3.0 - 7.1.0
abcd/abcd_.mp3 => XXXX/abcd_.mp3 abcd => XXXX asdasd/abcd.mp3 => asdasd/abcd.mp3 abcd. => abcd. blahahbasdabcd => blahahbasdXXXX