I\'m trying to replace parts of my string. But I met a problem when my search string start with same character:
$string = \"Good one :y. Keep going :y2\";
:y\b
Use this to replace only :y and not :y2.See demo.
:y
:y2
https://regex101.com/r/sJ9gM7/9
$re = "":y\\b"m"; $str = "Good one :y. Keep going :y2\n"; $subst = "a"; $result = preg_replace($re, $subst, $str);
Similarly for :y2 use :y2\b.
:y2\b