0

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

2 Answers 2

3

use (i.e. / in regex must be escaped using \/)

flipSlashes = shortLocString.replace(/\//g,"\\");

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, worked like a charm! thanks a bunch! I need to play around with that syntax. But I think it makes sense.
0

This will give you both ways

var shortLocString = "a/b//c/d//e///f////";
var shortLocString1 = shortLocString.replace(/\//g,"\\");
var shortLocString2 = shortLocString1.replace(/\\/g,"/");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.