gpt4 book ai didi

java - 当空格数量未知时,替代正向回顾

转载 作者:行者123 更新时间:2023-12-01 21:48:15 25 4
gpt4 key购买 nike

我的replacerRegex

("schedulingCancelModal": \{\s*? "title": ")(.+?)(?=")

正在获取正确的值,即 valueToBePicked: enter image description here

但是如何才能使 ("schedulingCancelModal":\{\s*? "title": ") 不像正向lookbehind那样包含在结果中?

到目前为止我的 Java 代码:

Pattern replacerPattern = Pattern.compile(replacerRegex);
Matcher matcher = replacerPattern.matcher(value);

while (matcher.find()) {
String valueToBePicked = matcher.group();
}

最佳答案

您只需选择 matcher.group(2) 即可获得第二个捕获组的内容。例如:

    String replacerRegex = "(\"schedulingCancelModal\": \\{\\s*? \"title\": \")(.+?)(?=\")";
String value = "\"valueToBePicked\": \"schedulingCancelModal\": {\n \"title\": \"Are you sure you want to leave scheduling?\", ... }";
Pattern replacerPattern = Pattern.compile(replacerRegex);
Matcher matcher = replacerPattern.matcher(value);

while (matcher.find()) {
String valueToBePicked = matcher.group(2);
System.out.println(valueToBePicked);
}

输出:

Are you sure you want to leave scheduling?

Demo on rextester

关于java - 当空格数量未知时,替代正向回顾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58775559/

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