replace function not working in regards of back slash

javascript node.js

27 观看

1回复

356 作者的声誉

This question already has an answer here:

below is my code code to replace black slash

var c = ';\&"%';
c = c.replace(/;/g,"w").replace(/\\/g,"e").replace(/&/g," and ").replace(/"/g,"e").replace(/%/g,"r");

expected output : we and rt

orignal output : w and rt

作者: pkd 的来源 发布者: 2017 年 9 月 15 日

回应 1


0

177209 作者的声誉

> var c = ';\&"%';
> c
';&"%'

Backslashes that aren’t part of recognized escapes don’t do anything. Escape the backslash.

var c = ';\\&"%';
作者: Ry- 发布者: 2017 年 9 月 15 日
32x32