Search and replace: fix a bug with text escaping