gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:24:46 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com