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.
Your 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:
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 \
.