# -*- coding: utf-8 -*-
import re
text = ur"הmאפrקt boom sam"
result = re.sub(ur'm\b', u'X', text, 0, re.UNICODE).encode("utf8")
print(result)