简体   繁体   English

JavaScript替换所有无法在Chrome中运行的实例

[英]JavaScript replace all instances not working in Chrome

Chrome is failing to replace all instances of the '_' string with '/' and I'm not sure why. Chrome无法将'_'字符串的所有实例替换为'/',但我不确定为什么。 I've got the g global operator and i case-insensitive operator. 我已经得到了g全球运营商和i不区分大小写的运营商。

var sample_string = 'mail/contacts/add/';
var p0 = sample_string.replace('_','/','gi');

First, you have mistaken something, either sample_string or replace call. 首先,您错误输入了sample_string或replace调用。

Second, flags are non standard and you should use regex with flags as first param instead flags as third param. 其次,标志是非标准的,您应将正则表达式与标志一起用作第一参数,而应将标志用作第三参数。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM