替换带引号的字符串中的所有逗号

125*_*748 1 javascript regex

有没有办法捕获和替换引号中包含的字符串中的所有逗号,而不是它之外的任何逗号.我想将它们更改为管道,但是这样:

/("(.*?)?,(.*?)")/gm

只获得第一个实例:

JSBIN

h2o*_*ooo 5

如果回调没问题,你可以这样做:

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)