java - 正则表达式 (java) 帮助

标签 java regex split

如何将此逗号+引号分隔的字符串拆分为一组字符串:

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,例如opencsvCommons CSV .

关于java - 正则表达式 (java) 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1949101/

相关文章:

java - 来自 JSONObject 的指定对象

java - 负向前瞻正则表达式不匹配特定模式

c# - 创建一个 Dev Express "simplified regular expression"

javascript - 对于多个空格,按照 typescript 中的正则表达式分割字符串无法按预期工作

Java 字符串用重复分隔符分割

java - 无法在 super 账本结构中调用链码

java - 发送多个非常小的数据包或更少的大数据包?

java - JPA 中 SUM 的最大值

javascript - 正则表达式匹配 : b: and c: in [Object a:var b:var c:var];

java - 如何按大小将csv文件拆分成多个文件