Another issue:
The code gets the message via $post->message.
Depending on installed Add-ons this might use a getter with modifies the value retrieved from the DB so preg_match / preg_replace may fail if the regex doesn't match the value retrieved from the getter (but would match the original DB value).
It might be better to (optionally) use $post->_message to bypass getters.