RegEx:用引号括起来的匹配逗号

时间:2017-07-30 13:37:37

标签: javascript regex

我有一个这样的字符串:

""a"","""b""",""12,3"","d"

我需要匹配引号括起来的所有逗号,无论引号的数量如何,结果都是:

a
b
12,3
d

2 个答案:

答案 0 :(得分:1)

您可以先尝试拆分字符串,然后替换部件中的引号



let s = '""a"","""b""",""12,3"","d"';

let r = s.split(/(?!,\w+),/);
r = r.map(e => e.replace(/"/g, ""));
console.log(r);




答案 1 :(得分:0)

这对我有用

var test = '""a"","""b""",""12,3"","d"'

test = test.match(/(\b[0-9a-z,]+)/gmi)

console.log('match: ', test)

匹配:['a','b','12','3','d']