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