Thank you, I ran into the same issue. I did a small change, since as mentioned below, this could cause issues with other backslashes, so I changed the code to:
stringEscapeBackslashes(s: string): string {
const escaped = s
.replace(/\\\[/g, '\\\\[')
.replace(/\\\]/g, '\\\\]')
.replace(/\\\(/g, '\\\\(')
.replace(/\\\)/g, '\\\\)');
return escaped;
}
(Wanted to put this in a comment, but I couldn't get the code to format.)