gpt4 book ai didi

java - 选择: but not including :之后 ""(含)内的所有文本

转载 作者:行者123 更新时间:2023-12-01 22:13:08 26 4
gpt4 key购买 nike

aa: {
one: "hello",
two: "good",
three: "bye",
four: "tomorrow",

},
"bb": {
"1": "a quick fox",
"2": "a slow bird",
"3": "a smart dog",
"4": "a wilf flowert",

我的数据类似于上面我想要选择的是 : 右侧“”内的所有文本,其中包括“”标记

我得到的是

: ("(.*?)")

但它选择了 : ,这也不是我想要的。

最佳答案

如果必须使用正则表达式,可以尝试Matcher.group()方法,如发现here .

public class TestClass {
public static void main(String[] args) {
String input = "aa: {\n" +
" one: \"hello\",\n" +
" two: \"good\",\n" +
" three: \"bye\",\n" +
" four: \"tomorrow\",\n" +
" },\n" +
" \"bb\": {\n" +
" \"1\": \"a quick fox\",\n" +
" \"2\": \"a slow bird\",\n" +
" \"3\": \"a smart dog\",\n" +
" \"4\": \"a wilf flowert\",\n";
// the actual code you need
Pattern pattern = Pattern.compile("(: )(\".+\")");
Matcher match = pattern.matcher(input);
while (match.find()) {
// here you go, only the value without the :
String value = match.group(2);
System.out.println("Found one = " + value);
}
}
}

这对我来说结果如下:

Found one = "hello"
Found one = "good"
Found one = "bye"
Found one = "tomorrow"
Found one = "a quick fox"
Found one = "a slow bird"
Found one = "a smart dog"
Found one = "a wilf flowert"

关于java - 选择: but not including :之后 ""(含)内的所有文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31527568/

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