I found the following question in one Java test package
Pattern p = Pattern.compile("[wow]*");
Matcher m = p.matcher("wow its cool");
boolean b = false;
while (b = m.find()) {
System.out.print(m.start() + " \"" + m.group() + "\" ");
}
where the output is as follows
0 "wow" 3 "" 4 "" 5 "" 6 "" 7 "" 8 "" 9 "oo" 11 "" 12 ""
Until the last match, it is clear that the pattern [wow] * greedily matches 0 or more characters 'w' and 'o', while to cancel characters, including spaces, it leads to empty lines. However, after comparing the last 'l' with 11 "the next 12" "seems unclear. There is no details in the test solution, and I couldnβt definitely figure it out from javadoc. My best guess is the border character, but I would appreciate it if could anyone give an explanation
source
share