Javascript 邮递员-更改字符串中出现的所有字符

Javascript 邮递员-更改字符串中出现的所有字符,javascript,postman,Javascript,Postman,在postman中,我希望将字符串中所有出现的斜杠更改为下划线 到目前为止,我已经编写了一个测试,它解析JSON响应并将我想要的字符串推送到一个数组中,从这里开始,我的代码如下所示 //an example string is below var string = "1/7842/0889#001"; // convert / to _ var slash = "/"; var newstring = string.replace (slash, "_"); // This just

在postman中,我希望将字符串中所有出现的斜杠更改为下划线

到目前为止,我已经编写了一个测试,它解析JSON响应并将我想要的字符串推送到一个数组中,从这里开始,我的代码如下所示

//an example string is below

var string =  "1/7842/0889#001";

// convert / to _
var slash = "/";
var newstring = string.replace (slash, "_");


// This just changes the first occurrence of the slash to an underscore
我试着使用“g”修饰语,但在《邮递员》中失败了

var newstring = string.replace (/slash/g, "_");
我想让这根绳子最后变成


“1_7842_0889#001”

用正斜杠将其拆分,并用
\uu

var string =  "1/7842/0889#001";

var strArray = string.split('/');

var newString = strArray.join("_");
还是一行

var newString = string.split('/').join("_");

您需要在regexp中用“\”转义
/

//下面是一个示例字符串
var string=“1/7842/0889#001”;
//转换成_
var newstring=string.replace(//\//g,“”);//打印1_7842_0889#001
console.log(新闻字符串)
所有正则表达式都将驻留在//
因此,对于您的问题,以下代码将有所帮助

Str.replace(/\/,“\”)

只需使用
string.replace(//\//g,'.''.'
)并参考原始问题。
User regular expression which will help  us to replace the characters globally by adding g
Added \/ just to escape it's value