I'd like to know if it is possible to retrieve values previously captured by a group, when that group has multiple occurences in a Pattern.
For example, say I have a pattern
({A}\\w{1})({B}\\w{1}){3}({E}\\w{1})
containing named groups A, B and E.
If I try to match the String ABCDE, it will produce a match. But when I want to retrieve the values, group A will contain value A, group B contains D and group E contains E, when I use the group(String groupName) method. In other words, I get only the value of the last occurence of group B. Is there any way I can retrieve both other values (B and C)?
Thanx in advance,
Abelhinha
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the quick reply, even though it's not the answer I hoped for:-)
I'm not sure that capturing the multiple occurrences in one group will solve my problem, since the reason I wanted multiple occurrences in the first place, is that group B contained named subgroups, with names that are meaningfull (fields of a table, the multiple occurrences referring to multiple rows in the table), but I can't have duplicate group names. I guess the only way out will be to append my own numbering to the subgroups, and deal with them that way.
Thanks again,
Abelhinha
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'd like to know if it is possible to retrieve values previously captured by a group, when that group has multiple occurences in a Pattern.
For example, say I have a pattern
({A}\\w{1})({B}\\w{1}){3}({E}\\w{1})
containing named groups A, B and E.
If I try to match the String ABCDE, it will produce a match. But when I want to retrieve the values, group A will contain value A, group B contains D and group E contains E, when I use the group(String groupName) method. In other words, I get only the value of the last occurence of group B. Is there any way I can retrieve both other values (B and C)?
Thanx in advance,
Abelhinha
Hi!
Answer: no.
The workaround is to capture possible values of B into a single group (i.e. "({B}\\w{3})" ) and analize it with another expression.
Regards
Hi,
Thanks for the quick reply, even though it's not the answer I hoped for:-)
I'm not sure that capturing the multiple occurrences in one group will solve my problem, since the reason I wanted multiple occurrences in the first place, is that group B contained named subgroups, with names that are meaningfull (fields of a table, the multiple occurrences referring to multiple rows in the table), but I can't have duplicate group names. I guess the only way out will be to append my own numbering to the subgroups, and deal with them that way.
Thanks again,
Abelhinha