As per our discussions today, while we could go with a solution where we loop over each character of the input String and append appropriate characters to a StringBuilder for the final result, it 1. looks cleaner with the current implementation and 2. would introduce more possibilities for bugs whereas the regex logic has been established for a long time. The difference in performance grows as the number of escapable characters grows, but the performance difference is most likely negligible for our use cases.