My code :
Pattern pattern = Pattern.compile(\"a?\");
Matcher matcher = pattern.matcher(\"ababa\");
while(matcher.find()){
System.out.println(matcher.star
The ?
is a greedy quantifier, therefore it will first try to match the 1-occurence before trying the 0-occurence. In you string,
It is a bit more complicated than that but that is the main idea. When the 1-occurence cannot match, it will then try with the 0-occurence.
As for the values of start, end and group, they will be where the match starts, ends and the group is what has been matched, so in the first 0-occurence match of your string, you get 1, 1 and the emtpy string. I am not sure this really answers your question.