Fix for \n replace bug (replace only replaces the first occurrence)

This fixes a problem that causes multiple \n to be ignored because only the first \n is replaced by "replace".