I have a suggestion like this:
Stan, Stanley, Stan!
I would like to replace all the words βStanβ by Peter with something like this
Peter, Stanley, Peter!
Here's my problem: Stanley cannot be replaced, because that is not Stan's word!
Now I am doing something like this:
$txt = preg_replace(array('/Stan/i', '/Jack/i'), array('Peter', 'Jennifer'), $txt);
but I need the regular expression to match only one word (which means that my word is not immediately followed by a letter).
I tried something like this / Stan ([^ [A-Za-z]) / i, but this render:
Peter Stanley, Peter
Some punctuation missing
source share