Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing backslashes from strings in javascript

I have a url in this format:

http:\/\/example.example.ru\/u82651140\/audio\/song.mp3

How can I remove the extra "\"s from the string? I have tried string.replace("\","") but that does not seem to do anything. If you could give me a JavaScript regular expression that will catch this, that would also work too. I just need to be able capture this string when it is inside another string.

like image 1000
Franz Payer Avatar asked Feb 02 '11 04:02

Franz Payer


People also ask

How do you escape a backslash in JavaScript?

Javascript uses '\' (backslash) in front as an escape character. To print quotes, using escape characters we have two options: For single quotes: \' (backslash followed by single quote) For double quotes: \” (backslash followed by double quotes)

How do I remove a strings slash in typescript?

Use the String. replace() method to remove a trailing slash from a string, e.g. str. replace(/\/+$/, '') .

How do you escape a string in JavaScript?

Using the Escape Character ( \ ) We can use the backslash ( \ ) escape character to prevent JavaScript from interpreting a quote as the end of the string. The syntax of \' will always be a single quote, and the syntax of \" will always be a double quote, without any fear of breaking the string.

What is JavaScript backslash?

The backslash ( \ ) escape character turns special characters into string characters: Code. Result.


1 Answers

Try

str = str.replace(/\\/g, '');
like image 100
Pointy Avatar answered Sep 22 '22 17:09

Pointy