Not without picking a different strategy.
If you decide that you’re going to use str.replace then you’ll end up with a big broken mess because the plan wasn’t sound to begin with.
this is why you disregard code. get your head out of the sand, start with a sound plan. then implement that.
but if you make a plan that makes sense, then that’s going to be something that can be implemented, and because you’ve planned it out you have a reference for what your code should be doing
the problem to be solving is the strategy. not the code. wrong problem to be looking at.