Java 当存在未知数量的空格时,可替代正向查找

Java 当存在未知数量的空格时,可替代正向查找,java,regex,Java,Regex,我的replacergex是 ("schedulingCancelModal": \{\s*? "title": ")(.+?)(?=") 正在提取正确的值,即valueToBePicked: 但是我如何才能像正向查找一样,不将(“schedulingCancelModal”:\{\s*?“title”:“包含在结果中 到目前为止,我的Java代码: Pattern replacerPattern = Pattern.compile(replacerRegex); Matcher match

我的
replacergex

("schedulingCancelModal": \{\s*? "title": ")(.+?)(?=")
正在提取正确的值,即
valueToBePicked

但是我如何才能像正向查找一样,不将
(“schedulingCancelModal”:\{\s*?“title”:“
包含在结果中

到目前为止,我的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?

它看起来像是JSON数据,为什么不直接使用JSON库呢?@Grace不用担心-我很高兴能帮上忙。