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,316
  • 4
  • 35
  • 53

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
  • 74,352
  • 26
  • 153
  • 180
Griffin
  • 13,184
  • 4
  • 29
  • 43
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
  • 74,352
  • 26
  • 153
  • 180
Robert
  • 8,717
  • 2
  • 27
  • 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