I got a simple javascript code :
'test1 {0} test2 test3'.replace('{0}', "test$'")
I expected the result to be test1 test$' test2 test3. But the result is test1 test test2 test3 test2 test3
This is absolutely normal. According to the mozilla documentation : https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace
The $' sequence has a signification in this case.
But i want to replace {0} with test$' exactly. I don’t want the $' sequence to be replace by something else. I have tried many ways :
'test1 {0} test2 test3'.replace('{0}', "test\$\'")
'test1 {0} test2 test3'.replace('{0}', "test\\$\\'")
'test1 {0} test2 test3'.replace('{0}', "test\u0024\u0027")
'test1 {0} test2 test3'.replace('{0}', "test\$'")
But nothing works.
How can i escape the $' sequence to avoid Firefox using it ?
From the page you cited:
So:
This works for me on JSFiddle.net.