23

I have the string: \rnosapmdwq\salesforce\R3Q\OutputFiles\Archive

I'm getting a unrecognized escape sequence when I try to send this to a .NET web service.

I'm trying to replace all of the "\" with "|" to send it to the server.

I know I can use the replace method but that only replaces the first element. I think I need to use a regular expression to solve it.

Here's what I have so far:

Path = Path.replace("\\/g", "|");

This is wrong though.

Nate
  • 2,306
  • 4
  • 35
  • 52

2 Answers2

51

You don't need to make a regex a string, and it helps having that first / in there

Path = Path.replace(/\\/g, "|")
Matt
  • 72,564
  • 26
  • 147
  • 178
Griffin
  • 11,022
  • 4
  • 29
  • 41
6

The correct syntax would be: Path = Path.replace(/\\/g, "|");

Working example at: http://jsfiddle.net/eDKej/.

Example (extra code for demonstration purposes only):

var Path = $("#path").text();
Path  = Path.replace(/\\/g, "|");
$("#new-path").append(Path);
Matt
  • 72,564
  • 26
  • 147
  • 178
Robert
  • 8,600
  • 2
  • 24
  • 34
  • Yeah, I actually noticed that after I posted my solution. I'm so used to having to replace forward slashes when submitting paths into a database. – Robert Aug 10 '11 at 17:42