我有一个正则表达式模式定义为
var pattern = ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))";
我正在尝试拆分一些类似 CSV 的字符串来获取字段
一些适用于此正则表达式的示例字符串是
_input[0] = ""; // expected single blank field
_input[1] = "A,B,C"; // expected three individual fields
_input[2] = "\"A,B\",C"; // expected two fields 'A,B' and C
_input[3] = "\"ABC\"\",\"Text with,\""; // expected two fields, 'ABC"', 'Text with,'
_input[4] = "\"\",ABC\",\"next_field\""; // expected two fields, '",ABC', 'next_field'
但是,这不起作用
_input[5] = "\"\"\",ABC\",\"next_field\"";
我期待三个领域
'"', 'ABC"', 'next_field'
但我得到了两个领域
'"",ABC', 'next_field'
任何人都可以帮助这个正则表达式吗?
我认为奇怪的部分是第二列在值的开头和结尾没有引号,只是在结尾处。所以第一列的值为空,第二列是ABC"
谢谢,罗伯