0

I have this string:

http:\/\/www.google.com\/

And i want to change the url to :

http://www.google.com/

With :

url = url.replace(/\\//gi, "/");

But it give me empty string.

Any idea how i can fix it?

1
  • by fixing the rege to /\\\//g: url.replace(/\\\//g,'/'), escape both the backslash and the regex delimiting forward slash Commented Jul 24, 2013 at 12:31

4 Answers 4

2

You need an extra backward slash. \

You could try this:

var url = 'http:\/\/www.google.com\/';
url.replace(/\\\//gi, "/");

JSFiddle Demo

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

Comments

1

Try:

window.unescape('http:\/\/www.google.com\/')

Note however that this is not strictly URL encoding that has been applied to this string, because the / character is perfectly legal there.

Did it perhaps come from JSON, where the / character is supposed to be escaped?

Comments

1

You're looking for decodeURI

decodeURI('http:\/\/www.google.com\/')
//"http://www.google.com/"

Comments

0

Use decodeURIComponent() function which decodes a URI component.

var url="http:\/\/www.google.com\/";
url=decodeURIComponent(url);

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.