Reputation: 167
I've got a line to flip all slashes in a string and it works great.
**flipSlashes = shortLocString.replace(/\\/g,"/");**
But if I want to flip them back, it falls apart. I've tried all of the following. I don't "get" the //g syntax very clearly, so don't know how to troubleshoot it.
**flipSlashes = shortLocString.replace(///g,"\\");**
**flipSlashes = shortUrlString.replace(/'/'/g,"\\");**
**flipSlashes = shortUrlString.replace(///g,"\\");**
Any help appreciated, dp
Upvotes: 0
Views: 39
Reputation: 121
This will give you both ways
var shortLocString = "a/b//c/d//e///f////";
var shortLocString1 = shortLocString.replace(/\//g,"\\");
var shortLocString2 = shortLocString1.replace(/\\/g,"/");
Upvotes: 0
Reputation: 2516
use (i.e. / in regex must be escaped using \/)
flipSlashes = shortLocString.replace(/\//g,"\\");
Upvotes: 3