Passing a function to String.replace()