Javascript code:
var testStr = "this is inside the {replace} expression";
var test2Str = "second $ short";
var test3Str = "third '$' short";
var test4Str = "third '$ ' short";
var test5Str = "third $' short";
var test6Str = "third '$$' short";
var test7Str = testStr.replace('{replace}', test2Str);
var test8Str = testStr.replace('{replace}', test3Str);
var test9Str = testStr.replace('{replace}', test4Str);
var test10Str = testStr.replace('{replace}', test5Str);
var test11Str = testStr.replace('{replace}', test6Str);
console.log("test2Str: " + test2Str);
console.log("test3Str: " + test3Str);
console.log("test4Str: " + test4Str);
console.log("test5Str: " + test5Str);
console.log("test6Str: " + test6Str);
console.log("test7Str: " + test7Str);
console.log("test8Str: " + test8Str);
console.log("test9Str: " + test9Str);
console.log("test10Str: " + test10Str);
console.log("test11Str: " + test11Str);
produces:
test2Str: second $ short
test3Str: third '$' short
test4Str: third '$ ' short
test5Str: third $' short
test6Str: third '$$' short
test7Str: this is inside the second $ short expression
test8Str: this is inside the third ' expression short expression
test9Str: this is inside the third '$ ' short expression
test10Str: this is inside the third expression short expression
test11Str: this is inside the third '$' short expression
for some reason the '$
causes the replace function to break the replacement string into two parts: one that is replaced in the correct location and the latter part at the end of the entire string. This behavior is the same in Chrome and in node
v10.16.2 command line. Any ideas? Are there any other escape characters that could cause similar problems?