[英]Replace All Same String Javascript
I want to Replace 2013-2-2
to 2013,2,2
我想将
2013-2-2
替换为2013,2,2
I tried 我试过了
var forrep = '2013-2-2';
var text = forrep.replace('-', ',');
but it only replaces the first -
the output looks like this 2013,2-2
但它只会替换第一个
-
输出看起来像这样2013,2-2
I want all the -
to be replaced by ,
commna 我希望所有的
-
要被替换,
commna
Please help Thanks 请帮忙谢谢
将正则表达式与/g
开关一起使用,以使其与“全局”匹配:
var text = forrep.replace(/-/g, ',');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.