有没有办法捕获和替换引号中包含的字符串中的所有逗号,而不是它之外的任何逗号.我想将它们更改为管道,但是这样:
/("(.*?)?,(.*?)")/gm
只获得第一个实例:
如果回调没问题,你可以这样做:
var str = '"test, test2, & test3",1324,,,,http://www.asdf.com';
var result = str.replace(/"[^"]+"/g, function (match) {
return match.replace(/,/g, '|');
});
console.log(result);
//"test| test2| & test3",1324,,,,http://www.asdf.com
Run Code Online (Sandbox Code Playgroud)