3v4l.org

run code in 300+ PHP versions simultaneously
<?php $needle = ':Name'; $str = ":Name :Name_en"; echo "Leading word boundary\t\t" . preg_replace("#\b$needle\b#", '"Test"', $str); echo "\n---\n"; echo "No leading word boundary\t" . preg_replace("#$needle\b#", '"Test"', $str); echo "\n---\n"; echo "Leading non-word boundary\t" . preg_replace("#\B$needle\b#", '"Test"', $str);
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Leading word boundary :Name :Name_en --- No leading word boundary "Test" :Name_en --- Leading non-word boundary "Test" :Name_en

preferences:
67.34 ms | 996 KiB | 4 Q