I have this string:
var someString = "23/03/2012";
and want to replace all the "/" with "-".
I tried to do this:
But it seems you cant have a forward slash
/ in there.
You need to escape your slash.
Try escaping the slash:
By the way -
/ is a (forward-)slash;
\ is a backslash.
First of all, that's a forward slash. And no, you can't have any in regexes unless you escape them. To escape them, put a backslash (
\) in front of it.
Remove all forward slash occurrences with blank char in
modelData = modelData.replace(/\//g, '');
You can just replace like this,
var someString = "23/03/2012"; someString.replace(/\//g, "-");
It works for me..
Just use the split - join approach:
Area.replace(new RegExp(/\//g), '-') replaces multiple forward slashes (
©2020 All rights reserved.