如何将此逗号+引号分隔的字符串拆分为一组字符串:
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 也是可以接受的。
最佳答案
您还可以使用众多开源小型库之一来解析 CSV,例如opencsv或Commons CSV .
关于java - 正则表达式 (java) 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1949101/