admin管理员组文章数量:1418371
I have a date and I want to replace all the slashes with dots. This is what I have but it's not working:
var TheDate = "3 / 29 / 2017";
TheDate = TheDate.replace(/'/'/g,'.');
alert(TheDate);
What's not right? There's a jsFiddle here to test.
I have a date and I want to replace all the slashes with dots. This is what I have but it's not working:
var TheDate = "3 / 29 / 2017";
TheDate = TheDate.replace(/'/'/g,'.');
alert(TheDate);
What's not right? There's a jsFiddle here to test.
Share Improve this question edited Jul 19, 2018 at 6:46 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Mar 30, 2017 at 0:05 frenchiefrenchie 52.1k117 gold badges320 silver badges528 bronze badges 04 Answers
Reset to default 3Your expression should be /\//g
var d = "3 / 29 / 2017";
d = d.replace(/\//g,'.');
document.body.append(d);
Replace /'/'/g
with /[/]/g
/
- start of the regex[/]
match characters inside square brackets/g
end of the regex
Regex resources:
- http://regexr./
- https://regexone./
Try this TheDate.replace(/\//g, '.')
var TheDate = "3 / 29 / 2017";
TheDate = TheDate.replace(/\//g,'.');
alert(TheDate);
You need to escape the /
character. You do it by prepending it with a \
.
本文标签: Replace slashes with dots in javascript regexStack Overflow
版权声明:本文标题:Replace slashes with dots in javascript regex - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745276620a2651225.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论