Search and replace logic.