The replace() function does allow regular expressions and it makes it much easier to read. I have to go test it out for @Stephanie’s request before I suggest an approach first. Without testing a REGEX I am loathe to suggest anything.
Nested solution work great. But they are very difficult to create in the editor because of formatting issues. And changing them sometimes creates more issues.