Reputation: 106
How can I convert the following URL string
[IpAddress]/Folder/\\2014\\5\\5\\abc\\\\cde\\efg\\\\IR12345676765454554\\123456.jpg]
to
[IpAddress]/Folder/2014/5/5/abc/cde/efg/IR12345676765454554/123456.jpg]
Thanks in advance.
Upvotes: 0
Views: 1098
Reputation: 382454
It looks like you want to replace every sequence of /
and \
into a single /
. Here's a way to do it :
str = str.replace(/[\/\\]+/g, '/');
EDIT
for your new question in which you don't want to replace the double /
of "http://"
(and I guess "file://"
, etc), you can do this :
str = str.replace(/(:?)([\/\\]+)/g, function(_,d,s){ return d ? d+s : '/' });
Upvotes: 1