I see even github gets confused about this :) 
I had 3 backslashes in the input and 4 and 6 backslashes in the output there.

For now I changed the regex so it replaces multiple backslashes. But it would become 4 backslashes then when 3 are in the string.

Addslashes might work, but that would also escape all the quotes. And that doesn't work for xpath (that's why we need to concat())