extract as findThenReplaceThenRun method