Questions.
1. When you say group, quantifiers for the group should not be considered. For example (a(b*))+, group(1) is not (a(b*))+ but (a(b*)).
2. If n>0, group returns the last match in the context of the previous match(group(n-1)), if no match in group(n-1), search n-2, on and on.
3. the below.
CharSequence inputStr = "abbabcd abbbabbbbcd";
String patternStr = "(a(b*))+(c*)";
while(matcher.find()) {
System.out.println("input string : " + inputStr);
System.out.println("pattern string : " + pattern.pattern());
pattern.pattern();
for(int i = 0; i <= matcher.groupCount(); i++) {
String groupStr = matcher.group(i);
System.out.println("group " + i + " : " + groupStr);
}
System.out.println("-------------");
}
result *************
input string : abbabcd abbbabbbbcd
pattern string : (a(b*))+(c*)
group 0 : abbabc
group 1 : ab
group 2 : b
group 3 : c
-------------
input string : abbabcd abbbabbbbcd
pattern string : (a(b*))+(c*)
group 0 : abbbabbbbc
group 1 : abbbb
group 2 : bbbb
group 3 : c
3. It's not what I expected. I think this way;
(a(b*))+(c*) matches abbabc and abbbabbbbc
and when I want group(0) for the first loop, this gives abbabc.
and group(1) gives abb because quantifier after the group notation is not considered in the group method.
and group(2) gives bb because the group(2) gives the first match in the previous match, in this case, abb, the result of group(1).
and group(3) gives c because the most previous match is from group(0), abbabc
and when I loop next
group(0) gives abbbabbbbc the second match.
group(1) gives abbb the first match out of the previous group(0)
group(2) gives bbb the first match out of the previous group(1)
group(3) gives c, the first match out of group(0), not group(2), nor group(1)
what's wrong?
Thanks.
1. When you say group, quantifiers for the group should not be considered. For example (a(b*))+, group(1) is not (a(b*))+ but (a(b*)).
2. If n>0, group returns the last match in the context of the previous match(group(n-1)), if no match in group(n-1), search n-2, on and on.
3. the below.
CharSequence inputStr = "abbabcd abbbabbbbcd";
String patternStr = "(a(b*))+(c*)";
while(matcher.find()) {
System.out.println("input string : " + inputStr);
System.out.println("pattern string : " + pattern.pattern());
pattern.pattern();
for(int i = 0; i <= matcher.groupCount(); i++) {
String groupStr = matcher.group(i);
System.out.println("group " + i + " : " + groupStr);
}
System.out.println("-------------");
}
result *************
input string : abbabcd abbbabbbbcd
pattern string : (a(b*))+(c*)
group 0 : abbabc
group 1 : ab
group 2 : b
group 3 : c
-------------
input string : abbabcd abbbabbbbcd
pattern string : (a(b*))+(c*)
group 0 : abbbabbbbc
group 1 : abbbb
group 2 : bbbb
group 3 : c
3. It's not what I expected. I think this way;
(a(b*))+(c*) matches abbabc and abbbabbbbc
and when I want group(0) for the first loop, this gives abbabc.
and group(1) gives abb because quantifier after the group notation is not considered in the group method.
and group(2) gives bb because the group(2) gives the first match in the previous match, in this case, abb, the result of group(1).
and group(3) gives c because the most previous match is from group(0), abbabc
and when I loop next
group(0) gives abbbabbbbc the second match.
group(1) gives abbb the first match out of the previous group(0)
group(2) gives bbb the first match out of the previous group(1)
group(3) gives c, the first match out of group(0), not group(2), nor group(1)
what's wrong?
Thanks.