Why doesn't this replace work?

Maybe share a link to the project with just this test script so we can debug it ourselves and report back.