[英]JavaScript does not replace the last symbol of the string
I have try to replace a symbol in JavaScript, but somehow this is always only replace the 1st symbol of the string instead of replaced all the symbol. 我试图替换JavaScript中的符号,但是总会以某种方式仅替换字符串的第一个符号,而不是替换所有符号。
JavaScript : JavaScript :
var note = "test'test'test'";
note = note .replace("'", "'");
Output : 输出 :
test'test'test'
Does anyone know how can I can replace all '
symbols with '
有谁知道我怎么能用
'
替换所有的'
符号 ?? ??
Use regex substitution and add a g
flag to make it global: 使用正则表达式替换并添加
g
标志使其全局:
> "test'test'test'".replace(/'/g, ''');
"test'test'test'"
试试这个笔记.replace(/ \\'/ g,''');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.