更换双反斜线与JavaScript的一个反斜杠斜杠、斜线、JavaScript

2023-09-10 17:48:18 作者:拿我同步干嘛!の拿给劳资抄呗!

我有以下问题:

我有一个执行一个AJAX请求到服务器的脚本,服务器返回 C:\在preVIEW备份\ 。然而,响应C:\\备份\\。不是一个真正的大问题,因为我只是想用单一换上双斜杠。我一直在寻找在这里堆栈,但我只能找到如何与双换上单反斜线,但我需要它周围的其他方法。

I have a script that executes an AJAX request to a server, the server returns C:\backup\ in the preview. However, the response is "C:\\backup\\". Not really a big deal, since I just thought to replace the double slashes with single ones. I've been looking around here on stack, but I could only find how to replace single backslashes with double ones, but I need it the other way around.

有人可以帮助我在这个问题上?

Can someone help me on this matter?

推荐答案

这应该这样做:C:\\备份\\代替(/ \\\\ /克,'\ \')

在正规前pression,一个 \ 必须逃到 \\ ,并在替换 \ 也。

In the regular expression, a single \ must be escaped to \\, and in the replacement \ also.