fix searchAndReplace()

fixes CID 28478 and 28566