我想设置一个模式,该模式将查找由第一次出现的“边界”限定的捕获组。但现在使用了最后一个边界。
例如:
String text = "this should match from A to the first B and not 2nd B, got that?";
Pattern ptrn = Pattern.compile("\\b(A.*B)\\b");
Matcher mtchr = ptrn.matcher(text);
while(mtchr.find()) {
String match = mtchr.group();
System.out.println("Match = <" + match + ">");
}
打印:
"Match = <A to the first B and not 2nd B>"
我想让它打印出:
"Match = <A to the first B>"
在模式内需要改变什么?