正则表达式:根据逗号解析CSV并忽略引号内的逗号 splitting a comma-separated string but ignoring commas in quotes

Categories: Java; Tagged with: ; @ January 30th, 2013 16:04

需求:解析CSV文件并忽略引号内的逗号

解决方案:

public static void main(String[] args) {
	String s = "a,b,c,\"1,000\"";
	String[] result = s.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
	for (String str : result) {
		System.out.println(str);
	}
}

输出:
a
b
c
“1,000”

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.