Not sure what you are asking.
One problem might be that the original value of input is changed. Should input's value be saved and the results of the replace() be stored in another variable?
...