I am trying to change the format of a date in a string from mm/dd/yyyy
to mm-dd-yyyy
.
I have tried using the following but it does not work
str.replace(///g,"-");
I am trying to change the format of a date in a string from mm/dd/yyyy
to mm-dd-yyyy
.
I have tried using the following but it does not work
str.replace(///g,"-");
Two problems :
/
in the regexUse
str = str.replace(/\//g, "-")
Since /
delimits the regular expression, if you want to use a /
character as data within one, you must escape it:
/\//g