我如何拆分此逗号+引号分隔字符串转换为一组字符串:正则表达式(JAVA)的帮助
String test = "[\"String 1\",\"String, two\"]";
String[] embeddedStrings = test.split("<insert magic regex here>");
//note: It should also work for this string, with a space after the separating comma: "[\"String 1\", \"String, two\"]";
assertEquals("String 1", embeddedStrings[0]);
assertEquals("String, two", embeddedStrings[1]);
我很好修剪方括号作为第一步。但问题是,即使我这样做了,我也不能只用逗号分割,因为嵌入的字符串可以包含逗号。 也可以使用Apache的StringUtils。
所以你的输出将总是'串1'和'串,两'?我想你有逗号分隔,引用封闭的字段。报价是可选的还是必需的? – jabbie 2009-12-22 21:31:17