「境界」の最初の出現によって制限されたキャプチャ グループを見つけるパターンを設定したいと考えています。しかし、今は最後の境界が使用されています。
例えば:
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>"
パターン内で何を変更する必要がありますか?