Fixed issue with replace-re when the source string contains ~ characters.