I am trying to use a regular expression (in php) to find a specific string, followed by a non-alphanumeric character (case insensitive).
Example String: Doggy is a lazy dog! Doggy. Dog and I. Search String: Dog Expected Result: Doggy is a lazy <a href="">dog</a>! Doggy. <a href="">Dog</a> and I.
Therefore, it must not match Doggy because the Dog substring is not accompanied by a non-alphanumeric character.
I am trying to do something in this direction, but it does not do exactly what I want.
preg_replace("/(dog)[^a-zA-Z0-9\s\p]/i/", "", $str);
source share