• I'd go with nested REPLACEs. It's not going to look nice but I don't think there's a better way.

    Perhaps wrap it in a Function if you need to reuse or to keep code tidy?