I want to replace a string by another. I found when the replaceValue contains "$"
, the replace will fail. So I am trying to escape "$"
by "$$"
first. The code is looks like this:
var str = ..., reg = ...;
function replaceString(replaceValue) {
str.replace(reg, replaceValue.replace(/$/g, '$$$$'));
}
But I think it is ugly since I need to write 4 dollar signs.
Is there any other charactors that I need to escape? And is there any better way to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…