Шаблон Java Regex, совпадающий с первым появлением «границы» после любой последовательности символов
Я хочу установить шаблон, который найдет группу захвата, ограниченную первым появлениемграница», Но теперь последняя граница используется.
Например.:
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 = <a to="" the="" first="" b="" and="" not="" 2nd="">"
</a>
"Match =
<a to="" the="" first="" b="">" </a>