Replace text patterns with a given replacement.