|There's more than one way to do things|
Answer: How do I delete the last instance of a word from a string?by Incognito (Pilgrim)
|on Nov 07, 2001 at 03:08 UTC||Need Help??|
Q&A > strings > How do I delete the last instance of a word from a string? - Answer contributed by Incognito
tye's regex solution works well, but you may want to modify it to:
to elimitate the extra space that's left when the word is removed. This leaves us with:
where the $word = "dog".
(Added by tye) Note that if the last occurance of that word is also the last word of a sentence, it will have whitespace in front of it and not behind it and this regex will fail. If the last occurance of the word is unlikely to be the first word in the string, then
would be a better choice.